• Creates permutations of the list.

    Type Parameters

    • A

    Parameters

    • list: List<A>

      The source list.

    Returns List<List<A>>

    The list having permutations.

    Examples

    import { empty, fromArray, permutations, range, toArray } from "./list.ts";
    import { assertEquals } from "../deps.ts";

    assertEquals(permutations(empty()), empty());

    const subSeq = permutations(range(1, 5));
    const sequences = toArray(subSeq).map((seq) => toArray(seq));
    assertEquals(sequences, [
    [1, 2, 3, 4],
    [2, 1, 3, 4],
    [3, 2, 1, 4],
    [2, 3, 1, 4],
    [3, 1, 2, 4],
    [1, 3, 2, 4],
    [4, 3, 2, 1],
    [3, 4, 2, 1],
    [3, 2, 4, 1],
    [4, 2, 3, 1],
    [2, 4, 3, 1],
    [2, 3, 4, 1],
    [4, 1, 2, 3],
    [1, 4, 2, 3],
    [1, 2, 4, 3],
    [4, 2, 1, 3],
    [2, 4, 1, 3],
    [2, 1, 4, 3],
    [4, 1, 3, 2],
    [1, 4, 3, 2],
    [1, 3, 4, 2],
    [4, 3, 1, 2],
    [3, 4, 1, 2],
    [3, 1, 4, 2],
    ]);

Generated using TypeDoc