List
zipWith()
Applies a binary function to corresponding elements of two lists and returns a new list.
- Type
- Details
The first parameter is a binary function
Returns a new list
- Example
const f = (a, b) => a + b;
zipWith(f, [1, 2, 3], [4, 5, 6]); //[5, 7, 9]const f = (a, b) => a + b;
zipWith(f, [1, 2, 3], [4, 5, 6]); //[5, 7, 9]zip()
Pairs elements from two lists into a new list of tuples.
- Type
- Details
Takes two lists
Returns a new list
This is equivalent to zipWith((a, b) => [a, b]).
- Example
zip([1, 2, 3], [4, 5, 6]); //[[1, 4], [2, 5], [3, 6]]zip([1, 2, 3], [4, 5, 6]); //[[1, 4], [2, 5], [3, 6]]join()
Joins elements in a list into a string, separated by a given delimiter.
- Type
- Details
The first parameter is a string that serves as the delimiter. The second parameter is a list. The function returns a string that joins all the elements in the list, separated by the delimiter.
- Example
join('|', [1, 2, 3]); //"1|2|3"join('|', [1, 2, 3]); //"1|2|3"slice()
Slices a section of a list.
- Type
- Details
Takes two integers representing the start and end indices, and returns a new list containing elements within the specified range.
- Example
slice(0, 3, [1, 2, 3, 4]); //[1, 2, 3]slice(0, 3, [1, 2, 3, 4]); //[1, 2, 3]take()
Takes the first
- Type
- Details
Takes an integer
- Example
take(3, [1, 2, 3, 4]); //[1, 2, 3]take(3, [1, 2, 3, 4]); //[1, 2, 3]takeWhile()
Takes elements from the beginning of a list as long as they satisfy a given predicate.
- Type
- Details
The first parameter is a predicate function
- Example
takeWhile((v) => v < 3, [1, 1, 4, 5, 1, 4]); //[1, 1]takeWhile((v) => v < 3, [1, 1, 4, 5, 1, 4]); //[1, 1]drop()
Drops the first
- Type
- Details
Takes an integer
- Example
drop(3, [1, 2, 3, 4]); //[4]drop(3, [1, 2, 3, 4]); //[4]dropWhile()
Drops elements from the beginning of a list as long as they satisfy a given predicate.
- Type
- Details
The first parameter is a predicate function
- Example
dropWhile((v) => v < 3, [1, 4, 5, 1, 4]); //[4, 5, 1, 4]dropWhile((v) => v < 3, [1, 4, 5, 1, 4]); //[4, 5, 1, 4]every()
Checks if all elements in a list satisfy a given predicate.
- Type
- Details
Takes a predicate function true if all elements in the list satisfy false otherwise.
- Example
every((v) => v < 3, [1, 1, 4, 5, 1, 4]); //falseevery((v) => v < 3, [1, 1, 4, 5, 1, 4]); //falsesome()
Checks if any element in a list satisfies a given predicate.
- Type
- Details
Takes a predicate function true if any element in the list satisfies false otherwise.
- Example
some((v) => v < 3, [1, 4, 5, 1, 4]); //truesome((v) => v < 3, [1, 4, 5, 1, 4]); //trueconcat()
Concatenates two lists.
- Type
- Details
Takes two lists and returns a new list that is a concatenation of the two.
- Example
concat([1, 2, 3], [4, 5, 6]); //[1, 2, 3, 4, 5, 6]concat([1, 2, 3], [4, 5, 6]); //[1, 2, 3, 4, 5, 6]concatr()
Concatenates two lists in reverse order.
- Type
- Details
Takes two lists and returns a new list that is a reverse concatenation of the two.
- Example
concatr([1, 2, 3], [4, 5, 6]); //[4, 5, 6
, 1, 2, 3]concatr([1, 2, 3], [4, 5, 6]); //[4, 5, 6
, 1, 2, 3]head()
Returns the first element of a list.
- Type
- Details
Takes a list and returns its first element.
- Example
head([1, 2, 3]); //1head([1, 2, 3]); //1tail()
Returns the last element of a list.
- Type
- Details
Takes a list and returns its last element.
- Example
tail([1, 2, 3]); //3tail([1, 2, 3]); //3dropHead()
Drops the first element of a list.
- Type
- Details
Takes a list and returns a new list with the first element removed.
- Example
dropHead([1, 2, 3]); //[2, 3]dropHead([1, 2, 3]); //[2, 3]dropTail()
Drops the last element of a list.
- Type
- Details
Takes a list and returns a new list with the last element removed.
- Example
dropTail([1, 2, 3]); //[1, 2]dropTail([1, 2, 3]); //[1, 2]includes()
Checks if a given element is present in a list.
- Type
- Details
Takes an element and a list, and returns true if the element is present in the list, and false otherwise.
- Example
includes(4, [1, 2, 3, 4]); //trueincludes(4, [1, 2, 3, 4]); //truereverse()
Reverses a list.
- Type
- Details
Takes a list and returns a new list with the elements in reverse order.
- Example
reverse([1, 2, 3]); //[3, 2, 1]reverse([1, 2, 3]); //[3, 2, 1]countWith()
Counts the number of elements in a list that satisfy a given predicate.
- Type
- Details
Takes a predicate function
- Example
countWith((v) => v === 5, [1, 2, 3, 4, 5, 5, 5]); //3countWith((v) => v === 5, [1, 2, 3, 4, 5, 5, 5]); //3count()
Counts the occurrences of a specific element in a list.
- Type
- Details
Takes an element and a list, and returns the number of occurrences of that element in the list.
- Example
count(5, [1, 2, 3, 4, 5, 5, 5]); //3count(5, [1, 2, 3, 4, 5, 5, 5]); //3pairList()
Pairs the first element with the rest of the elements in the list.
- Type
- Details
Takes a list and returns a pair consisting of its first element and the rest of the elements.
- Example
const [x, xs] = pairList([1, 2, 3, 4, 5]); // x=1, xs=[2, 3, 4, 5]const [x, xs] = pairList([1, 2, 3, 4, 5]); // x=1, xs=[2, 3, 4, 5]