Forio interview question

javascript algorithm