-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modularise nth, pluck, range and reverse functions
- Loading branch information
Showing
10 changed files
with
80 additions
and
11 deletions.
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,3 @@ | ||
const curry = require('./curry') | ||
|
||
module.exports = curry((i, xs) => xs[i]) |
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,3 @@ | ||
const curry = require('./curry') | ||
|
||
module.exports = curry((key, xs) => xs.map(o => o[key]).filter(x => x != null)) |
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,3 @@ | ||
const curry = require('./curry') | ||
|
||
module.exports = curry((start, end) => Array(end - start).fill(1).map((e, i) => i + start)) |
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 @@ | ||
module.exports = xs => [].concat(xs).reverse() |
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,15 @@ | ||
const assert = require('assert') | ||
const nth = require('../nth.js') | ||
const bf = require('../index.js') | ||
|
||
describe('nth', () => { | ||
|
||
it('is curried', () => { | ||
assert.strictEqual(nth(2)([1, 2, 3, 4]), 3); | ||
}) | ||
|
||
it('should retrieve third item in a list', () => { | ||
assert.strictEqual(nth(2, [1, 2, 3, 4, 5]), 3) | ||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
const assert = require('assert') | ||
const pluck = require('../pluck.js') | ||
const bf = require('../index.js') | ||
|
||
describe('pluck', () => { | ||
|
||
it('is curried', () => { | ||
assert.deepEqual(pluck('a')([{a: 1}, {a: 2}, {a: 3}]), [1, 2, 3]) | ||
}) | ||
|
||
it('should pluck values from list of objects', () => { | ||
const list = [{a: 1}, {a: 2}, {a: 3}] | ||
assert.deepEqual(bf.pluck('a', list), [1, 2, 3]) | ||
const list = [{a: 1}, {b: 2}, {a: 3}] | ||
assert.deepEqual(pluck('a', list), [1, 3]) | ||
}) | ||
|
||
it('is exported from the index file', () => { | ||
const list = [{a: 1}, {b: 2}, {a: 3}] | ||
assert.deepEqual(bf.pluck('a', list), [1, 3]) | ||
}) | ||
|
||
}) | ||
}) |
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,19 @@ | ||
const assert = require('assert') | ||
const range = require('../range.js') | ||
const bf = require('../index.js') | ||
|
||
describe('range', () => { | ||
|
||
it('is curried', () => { | ||
assert.deepEqual(range(1)(5), [1, 2, 3, 4]) | ||
}) | ||
|
||
it('should create a range from 1 to 5 exclusive', () => { | ||
assert.deepEqual(range(1, 5), [1, 2, 3, 4]) | ||
}) | ||
|
||
it('is exported from index', () => { | ||
assert.deepEqual(bf.range(1, 5), [1, 2, 3, 4]) | ||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
const assert = require('assert') | ||
const reverse = require('../reverse.js') | ||
const bf = require('../index.js') | ||
|
||
describe('reverse', () => { | ||
|
||
it('should reverse list', () => { | ||
it('should not mutate the list', () => { | ||
const list = [1, 2, 3, 4, 5] | ||
assert.deepEqual(bf.reverse(list), [5, 4, 3, 2, 1]) | ||
assert.notEqual(reverse(list), list) | ||
}) | ||
|
||
it('should not mutate argument', () => { | ||
it('should reverse the list', () => { | ||
const list = [1, 2, 3, 4, 5] | ||
assert.notEqual(bf.reverse(list), list) | ||
assert.deepEqual(reverse(list), [5, 4, 3, 2, 1]) | ||
}) | ||
|
||
it('should be exported from index', () => { | ||
const list = [1, 2, 3, 4, 5] | ||
assert.deepEqual(bf.reverse(list), [5, 4, 3, 2, 1]) | ||
}) | ||
}) |