Higher-order function to implement even and odd