I was trying to work out the algorithm used in the Python approach mentioned by @jeremydouglass
I think it is Heap’s algorithm so then I looked up Heap’s algorithm in Processing and found this: Storing all index permutations with Heap's algorithm
More follows.
And here is the Steinhaus–Johnson–Trotter algorithm in JS https://codepen.io/jbranchaud/pen/gbRGBp
and in ALGOL 60 !!! https://dl.acm.org/doi/10.1145/368637.368660