Medallia Interview Question

How would you advise simplifying this code?