Pergunta de entrevista da empresa Indeed

How would you do this in javascript?