Recursion code help

Hi everyone,
I’m trying to understand this function:
function string_recurse(active, rest) { if (rest.length == 0) { console.log(active); } else { string_recurse(active + rest.charAt(0), rest.substring(1, rest.length)); string_recurse(active, rest.substring(1, rest.length)); } }
This function print all character combinations from a string and it worked correctly. I try to understand following the code but the function will only print “abc” and '"" . Is there anyone can help me to understand it ? Thanks a lot :slight_smile:

It looks like it’s a variation or implementation of the Heap algorithm for permutations. Check it on Wikipedia (Heap algorithm)