Problem: 2626. 数组归约运算
12345678910111213
/** * @param {number[]} nums * @param {Function} fn * @param {number} init * @return {number} */var reduce = function(nums, fn, init) { var val=init for(i in nums){ val=fn(val,nums[i]) } return val};
1234567891011
/** * @param {number[]} nums * @param {Function} fn * @param {number} init * @return {number} */var reduce = function(nums, fn, init) { return nums.reduce((foldVar,value,index)=>{ return fn(foldVar,value) },init)};