2626. Array Reduce Transformation
UnknownView on LeetCode
Problem Overview
Array Reduce Transformation is a unknown-difficulty LeetCode problem. This is a common JavaScript pattern in coding interviews. Study the solution below and note the time and space complexity before attempting variations on your own.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Read the solution code below and trace through it on paper before submitting. For structured interview prep, follow our 30-day study guide.
2626.ts
TypeScript
type Fn = (accum: number, curr: number) => number
function reduce(nums: number[], fn: Fn, init: number): number {
let ans = init;
for (const num of nums) {
ans = fn(ans, num);
}
return ans;
};Was this solution helpful?
Related Problems
- 2625. Flatten Deeply Nested Array(Unknown)
- 2666. Allow One Function Call(Unknown)
- 2667. Create Hello World Function(Unknown)