fastest n choose n/2

by John Doe

JavaScript

function nchoosend2(n) {
    var k=n/2;
    var coeff = 1;
    var i;
    for (i = k+1; i <= n; i++) coeff *= i;
    for (i = 1;     i <= k; i++) coeff /= i;
    return coeff;
}
function nchoosend(n){
    var k=n/2;
    var coeff = 1;
    for (var i = 1;i<= k;i++) coeff *= k+i, coeff /= i; 
    return coeff;
}
n = 1000000000;
n = 10000;
console.time('a');
a = nchoosend2(n);
console.timeEnd('a');
console.time('b');
b = nchoosend(n)
console.timeEnd('b');
console.log(a+","+b)