• Type Parameters

    • T

    Parameters

    • input: readonly T[]

      the array to get permutations of

    Returns ROArrayArray<T>

    all of the permutations of an array

    Recursively calculates all of the permutations, does not cull duplicate entries.

    Only feasible for inputs of lengths 5 or so, since the number of permutations is (input.length)!, so will cause the stack to explode for longer inputs.

    This code could be made iterative using something like Steinhaus–Johnson–Trotter and additionally turned into a generator to reduce the stack size, but there is still a fundamental combinatorial explosion here that will affect runtime.

Generated using TypeDoc