freeCodeCamp Challenge Guide: Evaluate binomial coefficients

Evaluate binomial coefficients


Solutions

Solution 1 (Click to Show/Hide)
function binom(n, k) {
    return factorial(n)/(factorial(n-k)*factorial(k))
}

function factorial(n) {
  return n <= 1 ? 1 : n * factorial(n - 1);
}

This is based on the solution for the Factorial challenge, as the final answer is composed from three factorials. The factorials are calculated through a recursive, conditional loop until 1 is reached.

1 Like