Functional programming in JavaScript