@kingjs/descriptor.nested.array.reduce
v1.0.7
Published
Accumulates the values of an array tree using a callback.
Readme
@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?
): anyInterfaces
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 benullby 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: Thethisargument 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.reduceLicense
MIT
