##
RUNTIME: 54 ms, MEMORY: 42.3 MB
1
2
3
nums.forEach((el) => {
total = fn(total, el);
});
RUNTIME: 54 ms, MEMORY: 42.3 MB
1
2
3
for(let i of nums){
total = fn(total, i);
}
DEFINITION
The forEach() method of Array instances executes a provided function once for each array element
Syntax
forEach(callbackFn)
forEach(callbackFn, thisArg)
ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
https://leetcode.com/problems/array-reduce-transformation/