Function permutations

  • Builds all possible orders of all elements in the given array Ignores equality of elements, meaning this will always return the same number of permutations for a given length of input.

    Type Parameters

    • T

      The type of the elements in the array.

    Parameters

    • inputArray: Iterable<T, any, any>

      The array to build permutations from.

    Returns T[][]

    An array of all possible permutations of the given array.

    import { permutations } from "@std/collections/permutations";
    import { assertEquals } from "@std/assert";

    const numbers = [ 1, 2 ];
    const windows = permutations(numbers);

    assertEquals(windows, [
    [ 1, 2 ],
    [ 2, 1 ],
    ]);