Scientific Calculator

(public) bthiessen/factorial2

By bthiessen bthiessen

Double Factorial: Factorial function which only considers integers in the sequence of same parity (6!! = 6 x 4 x 2)

Tagged: enumerative combinatorics

factorial2 = function(n) {
  var x=1;
  if (n == 2) -> x = 2;
  if (n > 2) -> (
   while (n > 1) -> (
     x = x*n;
     n -= 2;
    );
  );
  x;
}

spam? | offensive?

0 Comments

Sign in to leave a comment