aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-05 19:31:59 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-05 19:31:59 +0000
commit1bfa30463e2741ba75270b7f0e379cf36970ed28 (patch)
tree314359f2fa1fec53ea3de7c5ad769e2b5069b923
parent2634 (diff)
downloadleetcode-1bfa30463e2741ba75270b7f0e379cf36970ed28.tar.gz
leetcode-1bfa30463e2741ba75270b7f0e379cf36970ed28.zip
2626
-rw-r--r--2626/main.js16
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;
+};