1.0.7 • Published 5 years ago

@kingjs/descriptor.nested.array.reduce v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@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

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 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.

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

Analytics