# How to evaluate binomial coefficient of two integers n and k in JavaScript ?

• Last Updated : 06 Apr, 2021

The following are the common definitions of Binomial Coefficients.

A binomial coefficient C(n, k) can be defined as the coefficient of x^k in the expansion of (1 + x)^n. Binomial coefficient C(n, k) also gives the number of ways, disregarding order, that k objects can be chosen from among n objects more formally, the number of k-element subsets (or k-combinations) of an n-element set.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Problem Statement: Write a function that takes two parameters n and k and returns the value of Binomial Coefficient C(n, k). For example, your function should return 6 for n = 4 and k = 2, and it should return 10 for n = 5 and k = 2.

Approach: Below are the steps to be followed in order to create a function that returns the binomial coefficient of two integers.

• Create a function that takes to arguments n and k.
• Now check whether the n and k are numbers. If both or one of them are not number then return NaN.
• Now check if k is less than 0 or k is greater than n. If one of the statements is true then return 0.
• Now check if the k is equal to 1 or k is equal to n. If one of the statements is true then return 1.
• Now check if is equal to 1 or k is equal to (n-1). If one of the statements is true then return n.
• Now write the logic to get the binomial coefficient.

Example:

## Javascript

 ``

Output:

`45`
My Personal Notes arrow_drop_up
Recommended Articles
Page :