Factorial Division

1. factorial problem

When playing on code war, meeting a problem which is called factorial division. Calculating the result of n!/d! (n>d). It’s easy, here is my solution:

1
2
3
4
5
6
7
function factorialDivision() {
  var result = 1;
  for(var i=n; i>d;i--) {
      result *= i;
  }
  return result;
}

Here is another solution using Recursive:

1
2
3
function factorialDivision(n, d) {
  return n==d && 1 || n * factorialDivision(n-1,d)
}

Excellent!