Pergunta de entrevista da empresa Affirm

How would you make this code more generic?