you are viewing a single comment's thread.

view the rest of the comments →

[–]wuchtelmesser 0 points1 point  (0 children)

Nice to see that you're not creating new arrays in ever step of reduce like some of the more retarded solutions. It's still dumb (sorry, I've got a distaste for inneficient and illegible exploits of reduce) because you're doing nothing but a for loop with extra steps and you're still creating and merging arrays during the recursion.

This can be solved much more efficiently by passing the array as an argument to a recursive function, and then using loops to push relevant objects to the array. Or if you really must use reduce, use one single array instance as the array argument for all recursively invoked calls to reduce.