Function combination

  • The number of ways to choose a sample of r elements from a set of n distinct objects where order does not matter.

    Parameters

    • n: number

      The number of objects. (n is an integer and n≥0)

    • r: number

      The size of the sample. (r is an integer and 0≤r≤n)

    • Optional options: {
          replacement?: boolean;
      }

      The options object.

      • Optional replacement?: boolean

        Allow for replacement or not.

    Returns number

    The number of combinations.

    Since

    0.1.0

    Example

    combination(5, 2)
    // => 10

    combination(5, 2, { replacement: true })
    // => 15