Code Lab

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

Ours or not

FácilErrors5 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.

Ejemplos

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

Devuelve 'Ann'

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

Devuelve 'guest'

Fuente

Cargando el editor…
  1. Without an error returns the result of load
  2. NotFoundError gives the fallback
  3. A TypeError goes on

Las pruebas ocultas se ejecutan al enviar