Test/eq stack results

function permute(rest, prefix = []) { if ( === 0) { return [prefix]; } return (rest .map((x, index) => { const oldRest = rest; const oldPrefix = prefix; // the `...` destructures the array into single values flattening it const newRest = [...(0, index), ...(index + 1)]; const newPrefix = [...prefix, x]; debugger; const result = permute(newRest, newPrefix); return result; }) // this step flattens the array of arrays returned by calling permute .reduce((flattened, arr) => [...flattened, ...arr], []) ); } (permute([1, 2, 3]));

Test/eq stack results

test/eq stack results

Media:

test/eq stack resultstest/eq stack resultstest/eq stack results