kingjs/descriptor.nested.array.reduce
@Accumulates the values of an array tree using a callback.
Usage
Return values of an array tree:
var reduce = require('@kingjs/descriptor.nested.array.reduce');
var result = reduce([
'a', [
'b', [
'c'
], 'd'
], 'e'
], (a, o) => {
a.push(o);
return a
}, [ ]);
result:
[ 'a', 'b', 'c', 'd', 'e' ]
API
declare function reduce(
tree: NestedArrays,
callback: (accumulator, value) => any,
initialValue?,
thisArg?
): any
Interfaces
-
NestedArray
: see @kingjs/descriptor/nested/array
Parameters
-
tree
: An array tree whose leaf values are accumulated. -
callback
: A callback invoked on each value accumulated. Return the newly accumulated value.-
accumulator
: The accumulated value so far. Will benull
by default. -
value
: The leaf being currently accumulated.
-
-
initialValue
: Value to use as the first argument of the callback. If no initial value is supplied, the first value visited will be used. -
thisArg
: Thethis
argument to pass tocallback
.
Returns
Returns the accumulated value or null
if no values were accumulated.
Install
With npm installed, run
$ npm install @kingjs/descriptor.nested.array.reduce
License
MIT