Async Reduce
Async Reduce
Implement an async version of Array.reduce that processes items sequentially.
Requirements:
- Implement
asyncReducethat takes array, async reducer, and initial value - Process items sequentially (wait for each async operation)
- Pass accumulated value and current item to reducer
- Return final accumulated value
Example:
const numbers = [1, 2, 3, 4];
const sum = async (acc, n) => acc + n;
asyncReduce(numbers, sum, 0).then(result => {
console.log(result); // 10
});
Examples:
Input 1:
{"array":[1,2,3,4],"initial":0}Output 1:
10Input 2:
{"array":[1,2,3],"initial":1}Output 2:
6Loading editor...
Run your code to see results
Click the Run button above