Tinkering with functional programming in JS