Cognizant Interview Question

Javascript code