-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Array/oddItem): Returns an array which contains every odd (secon…
…d) item of the original array.
- Loading branch information
Showing
5 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Returns an array which contains every odd (second) item of the original array. | ||
* @param {Array} arr | ||
* @returns {Array} | ||
*/ | ||
const fn = (arr) => arr.filter((arr, index) => index % 2 === 2 - 1); | ||
|
||
export default fn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { oddItem } from '../../src/array'; | ||
const test = require('ava'); | ||
|
||
|
||
test('returns en empty array it the array has only one item', t => { | ||
let input = ['foo']; | ||
let expectation = []; | ||
t.is(oddItem(input), expectation); | ||
}); | ||
|
||
test('returns every second item of a string with an even number of items', t => { | ||
let input = ['foo', 'bar', 'baz', 'foobar']; | ||
let expectation = ['bar', 'foobar']; | ||
t.deepEqual(oddItem(input), expectation); | ||
}); | ||
|
||
|
||
test('returns every second item of a string with an uneven number of items', t => { | ||
let input = ['foo', 'bar', 'baz', 'foobar', 'barbaz']; | ||
let expectation = ['bar', 'foobar']; | ||
t.deepEqual(oddItem(input), expectation); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters