According the documentation underscore-reduce I should pass three parameters.
For example:
var m = _.reduce([1,2,3], function (memo, num) {return (num * 2) +memo }, 0);
m; // 12 as expected
If I try to pass just the first two parameters I get a different value. Why?
var m = _.reduce([1,2,3], function (memo, num) {return (num * 2) +memo });
m; // 11 ..why?
With only two parameters passed into
reduce, it will use the first and second array items as arguments to the first function call.Usually you will pass the start value, but many operations have the same result when starting without their identity element. For example:
See also the docs for native
reduce().