Underscore.array
Functions
take _.arr.take(arr, key, def = undefined)
Collects values by key from each element of arr
.
var arr = name: 'foo' count: 10 name: 'bar' count: 20 name: 'baz';_arr; // ['foo', 'bar', 'baz']_arr; // [10, 20, 0]
dig _.arr.dig(arr, keys, def = undefined)
Collects values by multiple keys from each element of arr
.
var arr = item: elem: name: 'foo' item: elem: name: 'bar' item: elem: name: 'baz' item: null;_arr; // ['foo', 'bar', 'baz', 'DEF']
rotate _.arr.rotate(arr, count)
Returns a rotated copy of arr
.
_arr; // [4, 0, 1, 2, 3]_arr; // [2, 3, 4, 0, 1]
equal _.arr.equal(a, b, pred = undefined)
Returns true
if a
and b
have the same elements, the same number of elements, and are in the same order.
You can optionally pass a pred
function to check equality of elements. The operator ===
is used by default.
_arr; // true_arr; // false_arr; // true
same _.arr.same(a, b, pred = undefined)
Returns true
if a
and b
have the same elements and the same number of elements (ignores the order).
You can optionally pass a pred
function to check equality of elements. The operator ===
is used by default.
_arr; // true_arr; // true_arr; // true
sample _.arr.sample(arr)
Picks a random element from arr
.
_arr; // 1_arr; // 4_arr; // 2
samples _.arr.samples(arr, len)
Picks random elements from arr
.
_arr; // [2, 4, 0]_arr; // [1, 0, 2]_arr; // [4, 3, 0]