Enumerate an iterable.
In the case of arrays, enumerate(array)
is equivalent to array.entries()
.
iterator of [index, item] tuples
Creates a Map composed of keys generated from the results of running
each element of collection
through iteratee
. The corresponding value of
each key is a list of all elements responsible for generating the key. The
iteratee is invoked with one argument: (value).
To convert the result to an object, use Object.fromEntries(groupBy(...))
.
const array = [6.1, 4.2, 6.3];
groupBy(array, Math.floor)
// => [6, [6.1, 6.3]], [4, [4.2]]
collection item
group by key
Creates a Map composed of keys generated from the results of running
each element of collection
through iteratee
. The corresponding value of
each key is the last element responsible for generating the key. The
iteratee is invoked with one argument: (value).
To convert to an object, use Object.fromEntries(keyBy(...))
.
const array = [
{ 'id': '1', 'code': 97 },
{ 'id': '2', 'code': 100 }
]
keyBy(array, ({ id }) => id)
// => [['1', { 'id': '1', 'code': 97 }], ['2', { 'id': '2', 'code': 100 }]
collection item
group by key
A lazy iterator that evaluates the given generator only as far as needed and caches the results to return an item at index
Cartesian product of input iterables. Roughly equivalent to nested for-loops in a generator expression.
const z = product([1, 2, 3], [true, false]);
Array.from(z) //=> [[1, true], [2, true], [3, true], [1, false], [2, false], [3, false]]
Source: based on https://gist.github.com/cybercase/db7dde901d7070c98c48#gistcomment-3033459
Returns an iterator of numbers and is commonly used for looping a specific number of times in for loops. The API is the same as Python's range.
iterable iterator over range
Iterator that repeats item
times
number of times.
When times
is undefined, repeats indefinitely.
Takes n
items from iterator by calling next()
n
times and returns
an array of items. Stops iterating when iterator is exhausted.
Make an iterator that aggregates elements from each of the iterables. Source: https://dev.to/chrismilson/zip-iterator-in-typescript-ldm
const z = zip([1, 2, 3], 'abc');
Array.from(z) //=> [[1, 'a'], [2, 'b'], [3, 'c']]
Generated using TypeDoc
Create an object which calls a factory function when a non-existing key is accessed.