2626. Array Reduce Transformation
https://leetcode.com/problems/array-reduce-transformation
Javascript
var reduce = function(nums, fn, init) {
let accu = init
for (let i=0; i<nums.length; i++) {
accu = fn(accu, nums[i])
}
return accu
};
Typescript
type Fn = (accum: number, curr: number) => number
function reduce(nums: number[], fn: Fn, init: number): number {
let accu = init
for (let i=0; i<nums.length; i++) {
accu = fn(accu, nums[i])
}
return accu
};