Medallia interview question

How would you advise simplifying this code?