diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-01-05 19:31:59 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-01-05 19:31:59 +0000 |
commit | 1bfa30463e2741ba75270b7f0e379cf36970ed28 (patch) | |
tree | 314359f2fa1fec53ea3de7c5ad769e2b5069b923 /2626 | |
parent | 2634 (diff) | |
download | leetcode-1bfa30463e2741ba75270b7f0e379cf36970ed28.tar.gz leetcode-1bfa30463e2741ba75270b7f0e379cf36970ed28.zip |
2626
Diffstat (limited to '')
-rw-r--r-- | 2626/main.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/2626/main.js b/2626/main.js new file mode 100644 index 0000000..8cf9c86 --- /dev/null +++ b/2626/main.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node +"use strict"; + +/** + * * @param {number[]} nums + * * @param {Function} fn + * * @param {number} init + * * @return {number} + * */ +var reduce = function (nums, fn, init) { + let sum = init; + for (var i = 0; i < nums.length; i++) { + sum = fn(sum, nums[i]); + } + return sum; +}; |