Here is a recursive approach that uses backtracking to generate all distinct permutations of a set:
index.tsx790 chars28 lines
Here's an example of how to use this function:
index.tsx146 chars4 lines
This implementation handles sets of any size and works with any data type, as long as the elements of the set are comparable.
gistlibby LogSnag