Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion
Parallel requests
FacileAsync code5 min
The function load(id) loads a user and returns a promise with the user data. Write a function loadAll(ids, load) that starts loading all ids at once and returns a promise with an array of the results.
The results keep the order of ids, even when the answers arrive in another order.
Exemples
await loadAll([1, 2], (id) => Promise.resolve('user ' + id))Renvoie [ 'user 1', 'user 2' ]
await loadAll([], (id) => Promise.resolve(id))Renvoie []
Chargement de l'éditeur...
- Order of ids, though the answers arrive out of order
- All three loads run at the same time
Les tests cachés se lancent à la soumission