I want to make a permutation function in javascript that very quickly finds all permutations of an array, with every length before it (I'll give an example explaining this further). It needs to be as quick and efficient as possible, and should not have any duplicates. For example, the function would take an input of a list which would be like
[0, 1, 2]
and the expected output would be
[[0], [1], [2], [0, 1], [0, 2], [1, 2], [1, 2, 3]]
There wouldn't be any duplicates in the array (like [0, 0] wouldn't work), and swapped values shouldn't be there either ([1, 0] and [0, 1] both wouldn't be there. Only one of them).
I've looked at this question and this question but am still unable to get what I wanted.
The most important thing is that this needs to be as efficient as possible (take as little time to execute as possible)