const binomialCoefficient = (n: number, k: number) => {
        if (k < 0 || k > n) return 0;
        if (k === 0 || k === n) return 1;
        if (k === 1 || k === n - 1) return n;
        if (n - k < k) k = n - k;
        let res: number = n;
        for (let j: number = 2; j <= k; j++) res *= (n - j + 1) / j;
        return Math.round(res);
      };
      

      Typescript language logoCoefficient binomial

      Codiga's TypeScript Recipes

      Calculates the number of ways to choose k items from n items without repetition and without order.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.