I have been working through interview-style programming questions and wrote a little page to generate permutations of a string. Give it 1234 and it prints all twenty-four arrangements.
The recursive step is pretty simple: choose a character, find all the permutations of what is left, then put the chosen character at the beginning of each result. A one-character string is the stopping point. I store the results as object keys so repeated characters do not leave repeated answers in the output.
The first version takes its input from the query string and writes the answers straight into the document. Nothing fancy, but having the results on a page makes it easier to check the recursive reasoning against a few examples. It is also a good reminder that a short recursive function can produce a lot of output very quickly.