JSFiddle - React, Tailwind, and code Playground

HTML

<ul id='result'></ul>

JavaScript

function shuffle(arr) {
        var output = [];
        var n = arr.length;
        var ways = [];
        for(var i = 0, j = 1; i < n; ways.push(j *= ++i));
        var totalWays = ways.pop();
        for(var i = 0; i < totalWays; i++) {
                var copy = arr.slice();
                output[i] = [];
                for(var k = ways.length - 1; k >= 0; k--) {
                        var c = Math.floor(i/ways[k]) % (k + 2);
                        output[i].push(copy.splice(c,1)[0]);
                }
                output[i].push(copy[0]);
        }
        return output;
}

var result = shuffle(['a', 'b', 'c', 'd', 'e']);

document.getElementById("result").innerHTML = "<li>" + result.join("</li><li>") + "</li>";