Pergunta de entrevista da empresa Medallia

How would you advise simplifying this code?