aboutsummaryrefslogtreecommitdiffstats
path: root/2626/main.js
blob: 8cf9c8607e4bce4377920e3311379fa6aa3a1737 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
};