implementing a recursive reverse function in javascript
问题 I'm trying to write a function that reverses a list. The function is recursive. I know javascript does not have TCO, but i wanted to experiment with this anyway: reverse = function(list) { if (list.length < 2) { return list } fk = fork(list); return reverse(fk.tail).concat([fk.head]) } the fork function splits a list to a head and a tail: fork = function(list) {return {head: list[0], tail: list.slice(1)}} When I call reverse() with the list [1,2,3,4,5] , I get this result: reverse([1,2,3,4,5]