From 1bfa30463e2741ba75270b7f0e379cf36970ed28 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 5 Jan 2024 14:31:59 -0500 Subject: 2626 --- 2626/main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2626/main.js (limited to '2626') 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; +}; -- cgit v1.2.3