Code Lab

Modo entrevista. Temporizador de 3 min, sin pistas y sin autocompletado

Add two promises

FácilAsync code3 min

Write a function addTwoPromises(promise1, promise2). Each promise resolves with a number. Return a promise that resolves with the sum of the two numbers.

Ejemplos

await addTwoPromises(Promise.resolve(2), Promise.resolve(5))

Devuelve 7

Both promises resolve, and 2 plus 5 is 7.

Fuente

Cargando el editor…
  1. Promises of 2 and 5 give 7
  2. Promises that resolve after 100 and 50 ms

Las pruebas ocultas se ejecutan al enviar