Mathematics - Factorial

Math Domain

About

The factorial of a non-negative integer x is equal to the product of all integers less than or equal to x and greater than zero.

For example: factorial(4) would equal 4 * 3 * 2 * 1, which is 24.

In factorial, things are NOT repeated.

Number of combination from a set

It's used to calculate the number of combination in a set that permits to get the chance or probability.

If you have 3 elements [ a b c ], you have 6 possibilities or factorial 3:

  • a b c
  • a c b
  • b a c
  • b c a
  • c a b
  • c b a

You have therefore 1 change over 6 to pick the good combination.

Implementation

let factorial = function (n){
    if(n === 0 || n === 1){
        return 1;
    } else {
        return n * factorial(n-1);
    }
}

console.log(factorial(3));





Discover More
Thomas Bayes
Mathematics - Combination (Binomial coefficient|n choose k)

A combination is a selection of elements from a set where the order of selection does not matter. Order doesn't matter means that the selections AB and BA are considered a single combination (a single...
Thomas Bayes
Mathematics - Permutation (Ordered Combination)

A permutation is a selection of elements from a set where the order of selection matters. Order matters means that the selections AB and BA are considered as two differents selections. combination ...



Share this page:
Follow us:
Task Runner