From d370e379aa822f3da06aa2069358cf50c29a3c52 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:29:29 +0200 Subject: [PATCH 1/8] Specify `pop` --- tests/pop.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/pop.js diff --git a/tests/pop.js b/tests/pop.js new file mode 100644 index 0000000..3a6138d --- /dev/null +++ b/tests/pop.js @@ -0,0 +1,11 @@ +import { deepEqual } from 'assert'; +import pop from '../pop'; + +test('#pop', () => { + const array = [1, 2, 3]; + + deepEqual(pop(array) , [1, 2] ); + deepEqual(array , [1, 2, 3] ); + + deepEqual(pop([]) , [] ); +}); From 4add23850b09db61983c2a1477cd0b63ee9eebc5 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:35:06 +0200 Subject: [PATCH 2/8] Implement `pop` --- documentation/README.md | 21 +++++++++++++++++++++ module/index.js | 2 ++ module/pop.js | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 module/pop.js diff --git a/documentation/README.md b/documentation/README.md index a17c74a..d9db04f 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -52,6 +52,7 @@ - [pick](#pick) - [pipe](#pipe) - [plus](#plus) +- [pop](#pop) - [property](#property) - [reduce](#reduce) - [reduceFrom](#reducefrom) @@ -1001,6 +1002,26 @@ plus('a', 'b'); // => 'ab' +### pop + +Similar to `array.pop()`, but immutable. + +```js +import pop from '1-liners/pop'; + +const array = [1, 2, 3]; + +pop(array); // => [1, 2] +array; // => [1, 2, 3] +``` + +
+ Spec + • + Source: (array) => array.slice(0, -1); +
+ + ### property Same as `object[property]` diff --git a/module/index.js b/module/index.js index 525babd..581e366 100644 --- a/module/index.js +++ b/module/index.js @@ -45,6 +45,7 @@ import or from './or'; import pick from './pick'; import pipe from './pipe'; import plus from './plus'; +import pop from './pop'; import property from './property'; import reduce from './reduce'; import reduceFrom from './reduceFrom'; @@ -112,6 +113,7 @@ export { pick, pipe, plus, + pop, property, reduce, reduceFrom, diff --git a/module/pop.js b/module/pop.js new file mode 100644 index 0000000..f493fd0 --- /dev/null +++ b/module/pop.js @@ -0,0 +1,18 @@ +/** + * @module 1-liners/pop + * + * @description + * + * Similar to `array.pop()`, but immutable. + * + * @example + * + * import pop from '1-liners/pop'; + * + * const array = [1, 2, 3]; + * + * pop(array); // => [1, 2] + * array; // => [1, 2, 3] + * + */ +export default (array) => array.slice(0, -1); From 536202562ee8055b8e0a7f12bb7cd30358b3391e Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:35:49 +0200 Subject: [PATCH 3/8] Specify `shift` --- tests/shift.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/shift.js diff --git a/tests/shift.js b/tests/shift.js new file mode 100644 index 0000000..26da428 --- /dev/null +++ b/tests/shift.js @@ -0,0 +1,11 @@ +import { deepEqual } from 'assert'; +import shift from '../shift'; + +test('#shift', () => { + const array = [1, 2, 3]; + + deepEqual(shift(array) , [2, 3] ); + deepEqual(array , [1, 2, 3] ); + + deepEqual(shift([]) , [] ); +}); From b1eaf6ead83a0f275aa4d41c80ca1721f27ae32c Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:36:43 +0200 Subject: [PATCH 4/8] Implement `shift` --- documentation/README.md | 21 +++++++++++++++++++++ module/index.js | 2 ++ module/shift.js | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 module/shift.js diff --git a/documentation/README.md b/documentation/README.md index d9db04f..050d251 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -61,6 +61,7 @@ - [replace](#replace) - [shallowClone](#shallowclone) - [shave](#shave) +- [shift](#shift) - [some](#some) - [split](#split) - [tail](#tail) @@ -1170,6 +1171,26 @@ map(shave(1, parseInt), [0, 1.1, 2.2]); // => [0, 1, 2] +### shift + +Similar to `array.shift()`, but immutable. + +```js +import shift from '1-liners/shift'; + +const array = [1, 2, 3]; + +shift(array); // => [2, 3] +array; // => [1, 2, 3] +``` + +
+ Spec + • + Source: (array) => array.slice(1); +
+ + ### some Same as `[1,2,3].some(GreaterThan16)` diff --git a/module/index.js b/module/index.js index 581e366..3ca3a32 100644 --- a/module/index.js +++ b/module/index.js @@ -54,6 +54,7 @@ import reduceRight from './reduceRight'; import replace from './replace'; import shallowClone from './shallowClone'; import shave from './shave'; +import shift from './shift'; import some from './some'; import split from './split'; import tail from './tail'; @@ -122,6 +123,7 @@ export { replace, shallowClone, shave, + shift, some, split, tail, diff --git a/module/shift.js b/module/shift.js new file mode 100644 index 0000000..54c788f --- /dev/null +++ b/module/shift.js @@ -0,0 +1,18 @@ +/** + * @module 1-liners/shift + * + * @description + * + * Similar to `array.shift()`, but immutable. + * + * @example + * + * import shift from '1-liners/shift'; + * + * const array = [1, 2, 3]; + * + * shift(array); // => [2, 3] + * array; // => [1, 2, 3] + * + */ +export default (array) => array.slice(1); From 2005d8b701179b3dbd60feb93daf34e0d57c9d0c Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:43:17 +0200 Subject: [PATCH 5/8] Specify `last` --- tests/last.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/last.js diff --git a/tests/last.js b/tests/last.js new file mode 100644 index 0000000..050a542 --- /dev/null +++ b/tests/last.js @@ -0,0 +1,6 @@ +import { equal } from 'assert'; +import last from '../last'; + +test('#last', () => { + equal(last([1, 2, 3]), 3); +}); From f7d3c69237789b4a29ae435315b381465a25aa28 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 20 May 2015 22:44:37 +0200 Subject: [PATCH 6/8] Implement `last` --- documentation/README.md | 18 ++++++++++++++++++ module/index.js | 2 ++ module/last.js | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 module/last.js diff --git a/documentation/README.md b/documentation/README.md index 050d251..67d63c9 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -35,6 +35,7 @@ - [isUndefined](#isundefined) - [isUnknown](#isunknown) - [join](#join) +- [last](#last) - [length](#length) - [looseEqual](#looseequal) - [map](#map) @@ -688,6 +689,23 @@ join('-', [1, 'liners']); // => '1-liners' +### last + +Returns the last item of `array`. + +```js +var last = require('1-liners/last'); + +last([1, 2, 3]); // => 3 +``` + +
+ Spec + • + Source: (array) => array[array.length - 1]; +
+ + ### length Returns the length of an array. diff --git a/module/index.js b/module/index.js index 3ca3a32..5872819 100644 --- a/module/index.js +++ b/module/index.js @@ -28,6 +28,7 @@ import isTruthy from './isTruthy'; import isUndefined from './isUndefined'; import isUnknown from './isUnknown'; import join from './join'; +import last from './last'; import length from './length'; import looseEqual from './looseEqual'; import map from './map'; @@ -97,6 +98,7 @@ export { isUndefined, isUnknown, join, + last, length, looseEqual, map, diff --git a/module/last.js b/module/last.js new file mode 100644 index 0000000..eddd932 --- /dev/null +++ b/module/last.js @@ -0,0 +1,15 @@ +/** + * @module 1-liners/last + * + * @description + * + * Returns the last item of `array`. + * + * @example + * + * var last = require('1-liners/last'); + * + * last([1, 2, 3]); // => 3 + * + */ +export default (array) => array[array.length - 1]; From a1c7590ec7bb77f2593ec986f5f1bbe1e549c265 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Sat, 23 May 2015 15:39:26 +0200 Subject: [PATCH 7/8] Get rid of `shift` --- documentation/README.md | 21 --------------------- module/index.js | 2 -- module/shift.js | 18 ------------------ tests/shift.js | 11 ----------- 4 files changed, 52 deletions(-) delete mode 100644 module/shift.js delete mode 100644 tests/shift.js diff --git a/documentation/README.md b/documentation/README.md index 67d63c9..efd6f69 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -62,7 +62,6 @@ - [replace](#replace) - [shallowClone](#shallowclone) - [shave](#shave) -- [shift](#shift) - [some](#some) - [split](#split) - [tail](#tail) @@ -1189,26 +1188,6 @@ map(shave(1, parseInt), [0, 1.1, 2.2]); // => [0, 1, 2] -### shift - -Similar to `array.shift()`, but immutable. - -```js -import shift from '1-liners/shift'; - -const array = [1, 2, 3]; - -shift(array); // => [2, 3] -array; // => [1, 2, 3] -``` - -
- Spec - • - Source: (array) => array.slice(1); -
- - ### some Same as `[1,2,3].some(GreaterThan16)` diff --git a/module/index.js b/module/index.js index 5872819..094d945 100644 --- a/module/index.js +++ b/module/index.js @@ -55,7 +55,6 @@ import reduceRight from './reduceRight'; import replace from './replace'; import shallowClone from './shallowClone'; import shave from './shave'; -import shift from './shift'; import some from './some'; import split from './split'; import tail from './tail'; @@ -125,7 +124,6 @@ export { replace, shallowClone, shave, - shift, some, split, tail, diff --git a/module/shift.js b/module/shift.js deleted file mode 100644 index 54c788f..0000000 --- a/module/shift.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @module 1-liners/shift - * - * @description - * - * Similar to `array.shift()`, but immutable. - * - * @example - * - * import shift from '1-liners/shift'; - * - * const array = [1, 2, 3]; - * - * shift(array); // => [2, 3] - * array; // => [1, 2, 3] - * - */ -export default (array) => array.slice(1); diff --git a/tests/shift.js b/tests/shift.js deleted file mode 100644 index 26da428..0000000 --- a/tests/shift.js +++ /dev/null @@ -1,11 +0,0 @@ -import { deepEqual } from 'assert'; -import shift from '../shift'; - -test('#shift', () => { - const array = [1, 2, 3]; - - deepEqual(shift(array) , [2, 3] ); - deepEqual(array , [1, 2, 3] ); - - deepEqual(shift([]) , [] ); -}); From 9775c25bf28d19f1db35d14a382e0154457ad7e0 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Sat, 23 May 2015 15:40:17 +0200 Subject: [PATCH 8/8] Rename `pop` to `butLast` --- documentation/README.md | 42 ++++++++++++++++++++--------------------- module/butLast.js | 18 ++++++++++++++++++ module/index.js | 4 ++-- module/pop.js | 18 ------------------ tests/butLast.js | 11 +++++++++++ tests/pop.js | 11 ----------- 6 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 module/butLast.js delete mode 100644 module/pop.js create mode 100644 tests/butLast.js delete mode 100644 tests/pop.js diff --git a/documentation/README.md b/documentation/README.md index efd6f69..aff9c05 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -8,6 +8,7 @@ - [and](#and) - [bitAnd](#bitand) - [bitOr](#bitor) +- [butLast](#butlast) - [by](#by) - [compose](#compose) - [converge](#converge) @@ -53,7 +54,6 @@ - [pick](#pick) - [pipe](#pipe) - [plus](#plus) -- [pop](#pop) - [property](#property) - [reduce](#reduce) - [reduceFrom](#reducefrom) @@ -130,6 +130,26 @@ bitOr(1, 1); // => 1 +### butLast + +Return a copy of `array`, without the last item. + +```js +import butLast from '1-liners/butLast'; + +const array = [1, 2, 3]; + +butLast(array); // => [1, 2] +array; // => [1, 2, 3] +``` + +
+ Spec + • + Source: (array) => array.slice(0, -1); +
+ + ### by Same as `a / b` @@ -1020,26 +1040,6 @@ plus('a', 'b'); // => 'ab' -### pop - -Similar to `array.pop()`, but immutable. - -```js -import pop from '1-liners/pop'; - -const array = [1, 2, 3]; - -pop(array); // => [1, 2] -array; // => [1, 2, 3] -``` - -
- Spec - • - Source: (array) => array.slice(0, -1); -
- - ### property Same as `object[property]` diff --git a/module/butLast.js b/module/butLast.js new file mode 100644 index 0000000..0a4cd0f --- /dev/null +++ b/module/butLast.js @@ -0,0 +1,18 @@ +/** + * @module 1-liners/butLast + * + * @description + * + * Return a copy of `array`, without the last item. + * + * @example + * + * import butLast from '1-liners/butLast'; + * + * const array = [1, 2, 3]; + * + * butLast(array); // => [1, 2] + * array; // => [1, 2, 3] + * + */ +export default (array) => array.slice(0, -1); diff --git a/module/index.js b/module/index.js index 094d945..e89a6b2 100644 --- a/module/index.js +++ b/module/index.js @@ -1,6 +1,7 @@ import and from './and'; import bitAnd from './bitAnd'; import bitOr from './bitOr'; +import butLast from './butLast'; import by from './by'; import compose from './compose'; import converge from './converge'; @@ -46,7 +47,6 @@ import or from './or'; import pick from './pick'; import pipe from './pipe'; import plus from './plus'; -import pop from './pop'; import property from './property'; import reduce from './reduce'; import reduceFrom from './reduceFrom'; @@ -70,6 +70,7 @@ export { and, bitAnd, bitOr, + butLast, by, compose, converge, @@ -115,7 +116,6 @@ export { pick, pipe, plus, - pop, property, reduce, reduceFrom, diff --git a/module/pop.js b/module/pop.js deleted file mode 100644 index f493fd0..0000000 --- a/module/pop.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @module 1-liners/pop - * - * @description - * - * Similar to `array.pop()`, but immutable. - * - * @example - * - * import pop from '1-liners/pop'; - * - * const array = [1, 2, 3]; - * - * pop(array); // => [1, 2] - * array; // => [1, 2, 3] - * - */ -export default (array) => array.slice(0, -1); diff --git a/tests/butLast.js b/tests/butLast.js new file mode 100644 index 0000000..7b1d7f6 --- /dev/null +++ b/tests/butLast.js @@ -0,0 +1,11 @@ +import { deepEqual } from 'assert'; +import butLast from '../butLast'; + +test('#butLast', () => { + const array = [1, 2, 3]; + + deepEqual(butLast(array) , [1, 2] ); + deepEqual(array , [1, 2, 3] ); + + deepEqual(butLast([]) , [] ); +}); diff --git a/tests/pop.js b/tests/pop.js deleted file mode 100644 index 3a6138d..0000000 --- a/tests/pop.js +++ /dev/null @@ -1,11 +0,0 @@ -import { deepEqual } from 'assert'; -import pop from '../pop'; - -test('#pop', () => { - const array = [1, 2, 3]; - - deepEqual(pop(array) , [1, 2] ); - deepEqual(array , [1, 2, 3] ); - - deepEqual(pop([]) , [] ); -});