Meta interview question

optimize a function and a js related question.