2761. Array Reduce Transformation
My accepted JavaScript solution to LeetCode problem 2761, Array Reduce Transformation, running in 54ms.
- Difficulty: Easy
- JavaScript
- Runtime 54ms
- Memory 55.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 54ms, memory 55.7MB, accepted 2026-01-01.
/**
* @param {number[]} nums
* @param {Function} fn
* @param {number} init
* @return {number}
*/
var reduce = function(nums, fn, init) {
let result = init;
for (const num of nums) {
result = fn(result, num);
}
return result;
};