Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Promise.all Sum

Asynchronous JavaScriptmedium

Course · Section 16: Asynchronous JavaScript: Promises, Async/Await, and AJAX · Lecture 263: Promises and the Fetch API

Implement `sumAll(nums)` that wraps each number in a resolved promise, awaits them all with `Promise.all`, and returns the sum.

Sample tests

Input: sumAll([1,2,3])
Output: 6
Input: sumAll([])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • awaiting promises sequentially in a loop is slower than Promise.all.

Learning resources

  • MDN: Promise
Visualize this concept: Promises →
Approach & explanation (try first)

Promise.all resolves all values in parallel; reduce then sums the resolved array.

Loading...
⌘/Ctrl + Enter

Run your code to see results.