Cognizant Interview Question

One coding question and JavaScript concepts