Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69d5128 commit 97213c5Copy full SHA for 97213c5
JavaScript/6-reduce.js
@@ -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