array-reduce-x
Reduce an array (from left to right) to a single value.
Version: 1.0.0
Author: Xotic750 Xotic750@gmail.com
License: MIT
Copyright: Xotic750
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
var reduce = require('array-reduce-x');
var sum = reduce([0, 1, 2, 3], function (a, b) {
return a + b;
}, 0);