function myReduce(arr, fn, init) {
let acc = init;
for (const item of arr) acc = fn(acc, item);
return acc;
}
myReduce([1, 2, 3, 4], (sum, x) => sum + x, 0); // 10Reduce accumulates a result by applying a combining function to each element.
Reduce transforms an array into a single value by accumulating results.
Challenge: Implement myReduce that sums all elements in an array (using Array.prototype.reduce internally).