aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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;
+};