Accumulates the values of an array tree using a callback.
npm install @kingjs/descriptor.nested.array.reducejs
var reduce = require('@kingjs/descriptor.nested.array.reduce');
var result = reduce([
'a', [
'b', [
'c'
], 'd'
], 'e'
], (a, o) => {
a.push(o);
return a
}, [ ]);
`
result:
`js
[ 'a', 'b', 'c', 'd', 'e' ]
`
API
`ts
declare function reduce(
tree: NestedArrays,
callback: (accumulator, value) => any,
initialValue?,
thisArg?
): any
`
$3
- NestedArray: see [@kingjs/descriptor/nested/array][nested-array-descriptor]
$3
- 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 be null 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: The this argument to pass to callback.
$3
Returns the accumulated value or null if no values were accumulated.
Install
With npm installed, run
`
$ npm install @kingjs/descriptor.nested.array.reduce
``