Skip to content

Commit 38fc977

Browse files
author
James Halliday
committed
passing the reduce test now
1 parent 67406a4 commit 38fc977

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
var hasOwn = Object.prototype.hasOwnProperty;
2+
13
module.exports = function (xs, f, acc) {
2-
if (xs.reduce) return xs.reduce(f, acc);
4+
var hasAcc = arguments.length >= 3;
5+
if (hasAcc && xs.reduce) return xs.reduce(f, acc);
6+
if (xs.reduce) return xs.reduce(f);
7+
38
for (var i = 0; i < xs.length; i++) {
9+
if (!hasAcc) {
10+
acc = xs[i];
11+
hasAcc = true;
12+
}
413
if (!hasOwn.call(xs, i)) continue;
514
acc = f(acc, xs[i], i);
615
}
716
return acc;
817
};
9-
10-
var hasOwn = Object.prototype.hasOwnProperty;

0 commit comments

Comments
 (0)