Pregunta de entrevista de Uber

Asked to code in JavaScript