This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/array-reduce/index.js

19 lines
477 B
JavaScript

var hasOwn = Object.prototype.hasOwnProperty;
module.exports = function (xs, f, acc) {
var hasAcc = arguments.length >= 3;
if (hasAcc && xs.reduce) return xs.reduce(f, acc);
if (xs.reduce) return xs.reduce(f);
for (var i = 0; i < xs.length; i++) {
if (!hasOwn.call(xs, i)) continue;
if (!hasAcc) {
acc = xs[i];
hasAcc = true;
continue;
}
acc = f(acc, xs[i], i);
}
return acc;
};