Hola interview question

Refactor 25 lines function into smaller one