Array tools.
- Copyright:
- Mat. 2018-present
- License:
- Apache-2.0
- Source:
Methods
(inner) append(xs)
Append ys
to xs
and return xs.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
xs |
Array.<T>
|
Returns:
Concatenating function ys => xs . ys
(inner) countBy(arr, iterateeopt) → {Object.<String, Number>}
Create object composed of keys resulting from application
of iteratee
function to each element of the passed array arr
.
Values corresponds to the number of occurences of an element
in the passed array.
iteratee
is optional and defaults to identity
function.
Example:
countBy(
"exemplo plus quam ratione vivimus".split(" "),
w => w.length
)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
arr |
Array
|
|||
iteratee |
function
|
<optional> |
identity |
Returns:
- Type:
-
Object.<String, Number>
(inner) difference(a, b) → {Array}
Compute array as a
\ b
(set difference).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
|
b |
Array
|
Returns:
- Type:
-
Array
(inner) draw(arr) → {T|String}
Choose a random element from a non-empty array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<T>
|
String
|
Returns:
- Type:
-
T
|String
(inner) drop(n)
Drop the first n
elements of a given array or string.
Returns array or string without the first n
elements.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
Number
|
Returns:
Function which takes xs
and returns
array or string without the first n
elements.
(inner) dropLast(n)
Drop the last n
elements of a given array.
Returns array without the last n
elements.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
Number
|
Returns:
Function which takes xs
and returns
array or string without the last n
elements.
(inner) findDuplicates(arr, iterateeopt) → {Array.<String>}
Find duplicates in a given array.
Optionally, before comparision, each element is transformed by
iteratee
function (which defaults to identity
).
Example:
array.findDuplicates(["one", "two", "one", "three", "six", "two", "two"])
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
arr |
Array
|
|||
iteratee |
function
|
<optional> |
identity |
Returns:
- Type:
-
Array.<String>
(inner) flatten(arr) → {Array}
Simple array flattener.
[[1, 2,], ..., [3, 4,],] -> [1, 2, ..., 3, 4,]
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<Array>
|
Returns:
- Type:
-
Array
(inner) head(arr)
Return first element of the given array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<T>
|
String
|
Returns:
First element or type error is thrown.
(inner) init(arropt) → {Array.<T>|String}
Return array without its last element.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array.<T>
|
String
|
<optional> |
Returns:
- Type:
-
Array.<T>
|String
(inner) intersection(a, b) → {Array}
Compute array that is an intersection of a
and b
arrays.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
|
b |
Array
|
Returns:
- Type:
-
Array
(inner) isContinuous(arr, neighbouropt) → {Boolean}
Checks if a given array is a continuous block.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array.<T>
|
Array to check. |
|
neighbour |
function
|
<optional> |
Comparison function. |
Returns:
- Type:
-
Boolean
(inner) isSorted(arr, cmpopt) → {Boolean}
Checks if a given array is sorted.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array.<T>
|
Array to check. |
|
cmp |
function
|
<optional> |
Comparison function. |
Returns:
- Type:
-
Boolean
(inner) isSubset(a, b) → {Boolean}
Check if array a
is a subset of array b
.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
|
b |
Array
|
Returns:
- Type:
-
Boolean
(inner) last(arr)
Return the last element of the given array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array
|
String
|
Returns:
Last element or type error is thrown.
(inner) range(startopt, stop, stepopt) → {Array}
range(stop)
-> array of numbers; start defaults to0
range(start, stop[, step])
-> array of numbers
Return a list containing an arithmetic progression.
range(i, j)
returns[i, i+1, i+2, ..., j-1]
.
When step is given, it specifies the increment (or decrement). For example:
range(4)
returns[0, 1, 2, 3]
.
Imitates Python's range()
.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number
|
<optional> |
0 | |
stop |
Number
|
|||
step |
Number
|
<optional> |
1 |
Returns:
- Type:
-
Array
(inner) removeDuplicates(arr, iterateeopt) → {Array.<String>}
Create a new array with removed duplicates.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
arr |
Array
|
|||
iteratee |
function
|
<optional> |
identity |
Returns:
- Type:
-
Array.<String>
(inner) setEqual(a, b) → {Boolean}
Check set equality of two arrays treated as sets.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Array
|
|
b |
Array
|
Returns:
- Type:
-
Boolean
(inner) shuffle(arr) → {Array}
Shuffle all elements in the given array (Durstenfeld's modification to the Fisher-Yates shuffle algorithm).
The operation is taken in-place.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array
|
Returns:
- Type:
-
Array
(inner) sparse(startopt, stop, size) → {Array}
sparse(stop, size)
-> array of 'size' distinct integers in range[0..stop-1]
sparse(start, stop, size)
-> array of 'size' distinct integers in range[start..stop-1]
Generate sparse array of distinct integers with (almost) uniform distribution.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number
|
<optional> |
0 | |
stop |
Number
|
|||
size |
Number
|
Returns:
- Type:
-
Array
(inner) tail(arr) → {Array.<T>|String}
Return array without its head (first element).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array
|
String
|
Returns:
- Type:
-
Array.<T>
|String
(inner) take(n)
Take the first n
elements of a given array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
Number
|
Returns:
Function which takes xs
and return first n
elements
(inner) takeEvery(nth) → {function}
Take every nth
element from an arr
array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
nth |
Number
|
Returns:
- Type:
-
function
(any[]) => any[]
(inner) takeLast(n)
Take the last n
elements of a given array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
Number
|
Returns:
Function which takes xs
and return last n
elements
(inner) zip(…arrs) → {Array}
Zip given arrays.
Example:
zip([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])
[ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ], [ 4, 'd' ], [ 5, 'e' ] ]
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arrs |
Array
|
<repeatable> |
Arrays to zip. |
Returns:
- Type:
-
Array
(inner) zipWith(f) → {Funcion}
Zip given arrays using provided f
operator.
Example:
array.zipWith((a, b) => a + b) ([1, 2, 3, 4], [10, 20, 30, 40])
[ 11, 22, 33, 44 ]
- Source:
Parameters:
Name | Type | Description |
---|---|---|
f |
function
|
(...any[]) => any |
Returns:
- Type:
-
Funcion
(...any[][]) => any[]