Cognizant interview question

One coding question and JavaScript concepts