Stripe Interview Question

How would I optimize my code