Pregunta de entrevista de Indeed

How would you do this in javascript?