Fool me once, shame on you; fool me twice, shame on me!
Whenever you see yourself copying and pasting code more than once, consider refactoring your code into reusable functions. In the first two recipes of this chapter, we built single-purpose functions with hardcoded values. We can refactor our code into a collection of reusable functions.
In this recipe, we will refactor our two functions into generic ones by parameterizing them.