array-reduce-x

3.1.2 • Public • Published

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

array-reduce-x

Reduce an array (from left to right) to a single value.

module.exports*

This method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

Kind: Exported member
Returns: * - The value that results from the reduction.
Throws:

  • TypeError If array is null or undefined.
  • TypeError If callBack is not a function.
  • TypeError If called on an empty array without an initial value.
Param Type Description
array array The array to iterate over.
callBack function Function to execute for each element.
[initialValue] * Value to use as the first argument to the first call of the callback. If no initial value is supplied, the first element in the array will be used. Calling reduce on an empty array without an initial value is an error.

Example

import reduce from 'array-reduce-x';
 
console.log(
  reduce(
    [0, 1, 2, 3],
    function(a, b) {
      return a + b;
    },
    0,
  ),
); // sum is 6

/array-reduce-x/

    Package Sidebar

    Install

    npm i array-reduce-x

    Weekly Downloads

    208

    Version

    3.1.2

    License

    MIT

    Unpacked Size

    293 kB

    Total Files

    11

    Last publish

    Collaborators

    • xotic750