functional js recursion