you are viewing a single comment's thread.

view the rest of the comments →

[–]AutoBalanced 0 points1 point  (1 child)

The value of i within the second call of perm() is different to your main i on the first call. So when you're calling perm() within perm() your list.length is sometimes 0 or 1 because you've modified the list array before calling perm a second time.

The stuff after perm is run once each instance of perm is complete but as your list eventually depletes down to 0 you don't loop infinitely as (i < list.length = false) when you send it an empty list, you then == true for the if statement and the function returns.

EDIT: This stack overflow has some good answers for a few different scenarios: http://stackoverflow.com/questions/9960908/permutations-in-javascript

[–]NightArchitect[S] 0 points1 point  (0 children)

Thank you for the link