AKQA interview question

Asked to refactor the given code.