public
Created

An implementation of reduce modeled after the underscore.js api that does not default to Array.prototype.reduce.

  • Download Gist
reduce.js
JavaScript
1 2 3 4 5 6 7 8
function reduce(obj, iterator, memo, ctx) {
var keys = Object.keys(obj),
memo = memo || obj[keys[0]];
ctx = ctx || null;
for (var i = arguments[2] ? 0 : 1; i < keys.length; i++)
memo = iterator.call(ctx, memo, obj[keys[i]], keys[i], obj);
return memo;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.