solution to Enumerable exercise