Function permutations

  • Create all permutations of an array.

    Type Parameters

    • T

    Parameters

    • toPermute: readonly T[]

      The items that need to find a location. Initially all items are here.

    • prefix: readonly T[] = []

      The items that are already in the correct place. Initially this is empty. New items will be added to the end of this list.

    Returns Generator<readonly T[], void, undefined>

    Something you can iterate over to get all permutations of the original array.