UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

26 lines (25 loc) 657 B
// https://stackoverflow.com/a/37580979/17763661 export function allPermutationsOf(array) { const permutation = array.slice(); const length = permutation.length; const result = [permutation.slice()]; const c = new Array(length).fill(0); let i = 1; let k, p; while (i < length) { if (c[i] < i) { k = i % 2 && c[i]; p = permutation[i]; permutation[i] = permutation[k]; permutation[k] = p; ++c[i]; i = 1; result.push(permutation.slice()); } else { c[i] = 0; ++i; } } return result; }