Collect every failed lookup

A report needs a result for every lookup, including failed ones.

your task

Report every name in its original order. For each name, print its seat count or its lookup error. Finish with “failed: ” followed by the number of failed lookups.

Dover and Elm are both missing. The starter reports only Dover’s error and omits the rooms it found. Each entry in names starts an independent lookup.

Starter code
or press Ctrl EnterNot run yet

cases

Not run yetEvery room exists

Expected output

1Atlas: 8 seats
2Cedar: 12 seats
3failed: 0
See the input and the code for this case
const known = { Atlas: 8, Birch: 4, Cedar: 12 };
function findRoom(name) {
  if (name in known) return Promise.resolve({ name, seats: known[name] });
  return Promise.reject(new Error("No room named " + name));
}
const names = ["Atlas", "Cedar"];
Not run yetTwo rooms are missing

Expected output

1Atlas: 8 seats
2Dover: No room named Dover
3Birch: 4 seats
4Elm: No room named Elm
5failed: 2
See the input and the code for this case
const known = { Atlas: 8, Birch: 4, Cedar: 12 };
function findRoom(name) {
  if (name in known) return Promise.resolve({ name, seats: known[name] });
  return Promise.reject(new Error("No room named " + name));
}
const names = ["Atlas", "Dover", "Birch", "Elm"];