Unify interview question

You have to solve an algorithm problem based on javascript