@mirei/ts-collections
    Preparing search index...

    Function combinations

    • Generates the unique combinations that can be built from the elements in the sequence.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • Optionalsize: number

        Optional number of elements that each combination must contain. When omitted, combinations of every possible length are produced.

      Returns IEnumerable<IEnumerable<TElement>>

      A sequence of combinations built from the source elements.

      Thrown when size is negative.

      The source sequence is materialised before combinations are produced, so very large inputs can be expensive. Duplicate combinations produced by repeated elements are emitted only once.

      const numbers = [1, 2, 3];
      const combs = combinations(numbers, 2);
      console.log(combs.select(c => c.toArray()).toArray()); // [[1, 2], [1, 3], [2, 3]]