JSFiddle - React, Tailwind, and code Playground

by kflorence

JavaScript

var data = {
    "key1": [ 1, 2, 3, 4 ],
    "key2": [ 4, 5, 6, 7 ]
};

var arr = [ 1, 2, 3, 4 ];

function getPermutations( arr ) {
    var current = arr.slice( 0 ),
        i = 0,
        j = 0,
        k = 0,
        l = arr.length,
        set = [ arr ];

    while ( i < l ) {
        if ( k === l ) {
            k = 0;
            i++;
        }
        
        item = current.splice( j, 1 );
        current.unshift( item );
        set.push( current );
        k++;
    }

    return set;
}

console.log( getPermutations( arr ) );