Code Ninjas interview question

javascript question and problem solving