-
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.
Merge pull request #13 from svozza/includes-init-last-length
Modularise includes, init, last and length
- Loading branch information
Showing
9 changed files
with
68 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const curry = require('./curry') | ||
|
||
module.exports = curry((e, xs) => xs.indexOf(e) !== -1) |
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 @@ | ||
module.exports = xs => xs.slice(0, xs.length - 1) |
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 => xs[xs.length - 1] |
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 => xs.length |
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,18 @@ | ||
const assert = require('assert') | ||
const includes = require('../includes.js') | ||
|
||
describe('includes', () => { | ||
|
||
it('is curried', () => { | ||
assert.strictEqual(includes(1)([1, 2, 3, 4]), true) | ||
}) | ||
|
||
it('should indicate if the element is in the list', () => { | ||
assert.strictEqual(includes(1, [1, 2, 3, 4]), true) | ||
}) | ||
|
||
it('should indicate if the element is not in the list', () => { | ||
assert.strictEqual(includes(5, [1, 2, 3, 4]), false) | ||
}) | ||
|
||
}) |
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,16 @@ | ||
const assert = require('assert') | ||
const init = require('../init.js') | ||
|
||
describe('init', () => { | ||
|
||
it('does not mutate the original list', () => { | ||
const xs = [1, 2, 3, 4] | ||
const initxs = init(xs) | ||
assert.notStrictEqual(xs, initxs) | ||
}) | ||
|
||
it('should remove the last item of the list', () => { | ||
assert.deepEqual(init([1, 2, 3, 4, 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const assert = require('assert') | ||
const last = require('../last.js') | ||
|
||
describe('last', () => { | ||
|
||
it('should retrieve last item in a list', () => { | ||
assert.strictEqual(last([1, 2, 3, 4, 5]), 5) | ||
}) | ||
|
||
}) |
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,10 @@ | ||
const assert = require('assert') | ||
const length = require('../length.js') | ||
|
||
describe('length', () => { | ||
|
||
it('should return the length of a list', () => { | ||
assert.strictEqual(length([1, 2, 3, 4, 5]), 5) | ||
}) | ||
|
||
}) |