Module: Arrays

Arrays

Source:

Methods

<inner> coerce(arrayLikeObject) → {Array.<*>}

Coerces the given object (NodeList, arguments) to an array. This implementation works on modern browsers and IE >= 9. For IE < 9 a shim can be used, available here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Parameters:
Name Type Description
arrayLikeObject *
Source:
Returns:
Type
Array.<*>

<inner> contains(xs, x) → {boolean}

Returns true if the given Array `xs` contains the value `x`.
Parameters:
Name Type Description
xs Array
x * A value to search for in the given array.
Source:
Returns:
True of argument `x` is an element of the set `xs`.
Type
boolean

<inner> difference(xs, zs) → {Array}

Returns the relative difference of array `zs` in `xs`: All items in the array `xs` that are not contained in array `zs`.
Parameters:
Name Type Description
xs Array
zs Array
Source:
Returns:
The difference of the sets `xs` and `zs`.
Type
Array

<inner> equal(a, b, equalFn) → {boolean}

Does a shallow compare of two arrays.
Parameters:
Name Type Description
a Array An array to compare.
b Array A second array to compare with `a`.
equalFn function A custom comparison function that accepts two values a and b from the given arrays and returns true or false for equal and not equal respectively. If no equalFn is provided, the algorithm will use the strict equals operator.
Source:
Returns:
True if all items in a and b are equal, false if not.
Type
boolean

<inner> intersect(xs, zs) → {Array}

Returns all items in the array `xs` that are also contained in array `zs`.
Parameters:
Name Type Description
xs Array
zs Array
Source:
Returns:
The intersection of the sets `xs` and `zs`.
Type
Array

<inner> last(xs) → {*}

Returns the last item in the given Array.
Parameters:
Name Type Description
xs Array
Source:
Returns:
Last item in xs, or null if the given array is empty.
Type
*

<inner> mapcat(xs, fn) → {Array.<*>}

Like Array.prototype.map() except expects the given function to return arrays which will be concatenated together into the resulting array. Related to partition() in the sense that mapcat(partition(xs, n), identity) == xs. Don't use Array.prototype.concat.apply(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply "The consequences of applying a function with too many arguments (think more than tens of thousands of arguments) vary across engines (JavaScriptCore has hard-coded argument limit of 65536), because the limit (indeed even the nature of any excessively-large-stack behavior) is unspecified. "
Parameters:
Name Type Description
xs Array.<*>
fn function
Source:
Returns:
Type
Array.<*>

<inner> partition(xs, n) → {Array.<Array.<*>>}

Partitions the given array xs into an array of arrays where each nested array is a subsequence of xs of length n. See mapcat().
Parameters:
Name Type Description
xs Array.<*>
n number
Source:
Returns:
Type
Array.<Array.<*>>

<inner> second(xs) → {*}

Returns the second item in the given array.
Parameters:
Name Type Description
xs Array
Source:
Returns:
Type
*

<inner> some(xs, pred) → {*}

Similar to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some Except, instead of returning true, returns the first value in the array for which the `pred` returns true.
Parameters:
Name Type Description
xs Array.<*>
pred function
Source:
Returns:
One of xs
Type
*

<inner> someIndex(xs, pred) → {*}

Similar to some(), except that it returns an index into the given array for the first element for which `pred` returns true. If none return true, -1 is returned.
Parameters:
Name Type Description
xs Array.<*>
pred function
Source:
Returns:
Type
*

<inner> split(list, predicate) → {Array.<Array.<*>>}

Splits the list into two parts using the given predicate. The first element will be the "prefix," containing all elements of `list` before the element that returns true for the predicate. The second element is equal to dropWhile(list).
Parameters:
Name Type Description
list Array.<*>
predicate function
Source:
Returns:
The prefix and suffix of `list`
Type
Array.<Array.<*>>