Playing around with functional programming in Javascript