Skip to content

Commit fc47ab5

Browse files
authored
Create 2626-array-reduce-transformation.js
1 parent c071774 commit fc47ab5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {Function} fn
4+
* @param {number} init
5+
* @return {number}
6+
*/
7+
var reduce = function (nums, fn, init) {
8+
ans = init;
9+
for (let n of nums)
10+
ans = fn(ans, n);
11+
return ans;
12+
};

0 commit comments

Comments
 (0)