Skip to content

Commit 97213c5

Browse files
committed
Add reduce example
1 parent 69d5128 commit 97213c5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

JavaScript/6-reduce.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const reduce = (fn, acc, [cur, ...rest]) => (
4+
cur === undefined ? acc : reduce(fn, fn(acc, cur), rest)
5+
);
6+
7+
const res = reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
8+
console.log({ res });

0 commit comments

Comments
 (0)