-
Notifications
You must be signed in to change notification settings - Fork 1
Docs
Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
array (Array): The array to process.
[size=1] (number): The length of each chunk
(Array): Returns the new array of chunks.
_:chunk({'a', 'b', 'c', 'd'}, 2)
// => {{'a', 'b'}, {'c', 'd'}}
_:chunk({'a', 'b', 'c', 'd'}, 3)
// => {{'a', 'b', 'c'}, {'d'}}
Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.
array (Array): The array to compact.
(Array): Returns the new array of filtered values.
_:compact({ 0, 1, .F., 2, "", 3, Nil })
// => {1, 2, 3}
Creates a new array concatenating array with any additional arrays and/or values.
array (Array): The array to concatenate.
[values] (...*): The values to concatenate.
(Array): Returns the new concatenated array.
array := {1}
other := _:concat(array, 2, {3}, {{4}})
// other
// => {1, 2, 3, {4}}
//array
// => {1}
Creates a slice of array with n elements dropped from the beginning.
array (Array): The array to query.
[n=1] (number): The number of elements to drop.
(Array): Returns the slice of array.
_:drop({1, 2, 3})
// => {2, 3}
_:drop({1, 2, 3}, 2)
// => {3}
_:drop({1, 2, 3}, 5)
// => {}
_:drop({1, 2, 3}, 0)
// => {1, 2, 3}
Creates a slice of array with n elements dropped from the end.
array (Array): The array to query.
[n=1] (number): The number of elements to drop.
(Array): Returns the slice of array.
_:dropRight({1, 2, 3})
// => {1, 2}
_:dropRight({1, 2, 3}, 2)
// => {1}
_:dropRight({1, 2, 3}, 5)
// => {}
_:dropRight({1, 2, 3}, 0)
// => {1, 2, 3}
Fills elements of array with value from start up to, but not including, end.
Note: This method mutates array.
array (Array): The array to fill.
value (*): The value to fill array with.
[start=0] (number): The start position.
[end=Len(array)] (number): The end position.
(Array): Returns array.
Local array := {1, 2, 3}
_:fill(array, 'a')
//array
// => {'a', 'a', 'a'}
_:fill(Array(3), 2)
// => {2, 2, 2}
_:fill({4, 6, 8, 10}, '*', 2, 4)
// => {4, '*', '*', 10}
Flattens array a single level deep.
array (Array): The array to flatten.
(Array): Returns the new flattened array.
_:flatten({1, {2, {3, {4}}, 5}})
// => {1, 2, {3, {4}}, 5}
Recursively flattens array.
array (Array): The array to flatten.
(Array): Returns the new flattened array.
_:flattenDeep({1, {2, {3, {4}}, 5}})
// => {1, 2, 3, 4, 5}
Recursively flatten array up to depth times.
array (Array): The array to flatten.
[depth=1] (number): The maximum recursion depth.
(Array): Returns the new flattened array.
array := {1, {2, {3, {4}}, 5}}
_:flattenDepth(array, 1)
// => {1, 2, {3, {4}}, 5}
_:flattenDepth(array, 2)
// => {1, 2, 3, {4}, 5}
Gets the first element of array.
_:first
array (Array): The array to query.
(*): Returns the first element of array.
_:head({1, 2, 3})
// => 1
_:head({})
// => Nil