JavaScript functional programing.
__.chunk
__.compact
__.compactDeep
__.concat
__.difference
__.drop
__.dropRight
__.dropRightWhile
Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
__.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
__.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.
__.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
Same as __.compact
but remove the flasey values recursively.
__.compactDeep([0, 1, false, 2, '', 3, [false, 22, '', 33], 4, false, 7]);
// => [1, 2, 3, [22, 33], 4, 7]
Creates a new array concatenating array with any additional arrays and/or values.
var array = [1];
var other = __.concat(array, 2, [3], [[4]]);
console.log(other);
// => [1, 2, 3, [4]]
console.log(array);
// => [1]
Creates an array of array values not included in the other given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.
__.difference([2, 1], [2, 3]);
// => [1]
Creates a slice of array with n elements dropped from the beginning.
__.drop([1, 2, 3]);
// => [2, 3]
__.drop([1, 2, 3], 2);
// => [3]
__.drop([1, 2, 3], 5);
// => []
__.drop([1, 2, 3], 0);
// => [1, 2, 3]
Creates a slice of array with n elements dropped from the end.
__.dropRight([1, 2, 3]);
// => [1, 2]
__.dropRight([1, 2, 3], 2);
// => [1]
__.dropRight([1, 2, 3], 5);
// => []
__.dropRight([1, 2, 3], 0);
// => [1, 2, 3]
Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
__.dropRightWhile(users, function(o) { return !o.active; });
// => objects for ['barney']
// The `_.matches` iteratee shorthand.
__.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
// => objects for ['barney', 'fred']