Exercise in functional JavaScript while reading Functional JavaScript by Michael Fogus