@mikuroxina/mini-fn
    Preparing search index...

    Function permutations

    • Creates permutations of the list.

      Type Parameters

      • A

      Parameters

      Returns List.List<List.List<A>>

      The list having permutations.

      Examples

      expect(permutations(empty())).toStrictEqual(empty());

      const subSeq = permutations(range(1, 5));
      const sequences = toArray(subSeq).map((seq) => toArray(seq));
      expect(sequences).toStrictEqual([
      [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],
      ]);