Sulopa Solutions interview question

they ask me to solve the problem on JavaScript