Skip to content

Commit e833882

Browse files
author
James Halliday
committed
passing the cippled tests
1 parent 38fc977 commit e833882

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ module.exports = function (xs, f, acc) {
66
if (xs.reduce) return xs.reduce(f);
77

88
for (var i = 0; i < xs.length; i++) {
9+
if (!hasOwn.call(xs, i)) continue;
910
if (!hasAcc) {
1011
acc = xs[i];
1112
hasAcc = true;
13+
continue;
1214
}
13-
if (!hasOwn.call(xs, i)) continue;
1415
acc = f(acc, xs[i], i);
1516
}
1617
return acc;

test/reduce.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var reduce = require('../');
22
var test = require('tape');
33

44
test('numeric reduces', function (t) {
5-
t.plan(3);
5+
t.plan(6);
66

77
var xs = [ 1, 2, 3, 4 ];
88
t.equal(
@@ -17,4 +17,23 @@ test('numeric reduces', function (t) {
1717
reduce(xs, function (acc, x) { return acc + x }),
1818
10
1919
);
20+
21+
var ys = cripple([ 1, 2, 3, 4 ]);
22+
t.equal(
23+
reduce(ys, function (acc, x) { return acc + x }, 0),
24+
10
25+
);
26+
t.equal(
27+
reduce(ys, function (acc, x) { return acc + x }, 100),
28+
110
29+
);
30+
t.equal(
31+
reduce(ys, function (acc, x) { return acc + x }),
32+
10
33+
);
2034
});
35+
36+
function cripple (xs) {
37+
xs.reduce = undefined;
38+
return xs;
39+
}

0 commit comments

Comments
 (0)