Affirm Interview Question

How would you make this code more generic?