blob: 8cf9c8607e4bce4377920e3311379fa6aa3a1737 (
plain) (
tree)
|
|
#!/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;
};
|