Code Lab

Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion

Ours or not

FacileErrors5 min

The code already has a class NotFoundError. Write a function loadOr(load, fallback). It calls load() and returns the result. If load() throws a NotFoundError, return fallback. Any other error goes on as it is.

Exemples

loadOr(() => 'Ann', 'guest')

Renvoie 'Ann'

loadOr(() => { throw new NotFoundError('no user 7'); }, 'guest')

Renvoie 'guest'

Source

Chargement de l'éditeur...
  1. Without an error returns the result of load
  2. NotFoundError gives the fallback
  3. A TypeError goes on

Les tests cachés se lancent à la soumission