Skip to content

Commit 516b8cc

Browse files
committed
Solution for q4
1 parent e4787f0 commit 516b8cc

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

assignments/q4-reduce.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
function reduce (xs, fn, seed) {
2-
// NOTE: that seed is optional; you should give the appropriate default in the function body
3-
// ...
4-
}
2+
var memo = seed;
3+
for (var i = !memo ? 1 : 0; i < xs.length; i++) {
4+
memo = fn(!memo ? xs[0] : memo, xs[i]);
5+
}
6+
return memo;
7+
}

0 commit comments

Comments
 (0)