Here you can find the source of factorial()
Number.prototype.factorial = function() { var n = 1;//from w w w.ja v a 2 s. com for(var i = 2; i <= this; i++) n*=i; return n; } Number.prototype.permutation = function(r) { return (this.factorial() / (this-r).factorial()) } function permutate(p) { var states = new Number(p.length) console.log( states.permutation(states) ) } function proofRow(n, pvar, rule ) { var s = n + "\t" + pvar + "\t" + rule console.log(s) } module.exports = { chat: function chat() { var argsv = chat.arguments var s="" for(var ea in argsv) { if(argsv[ea] != undefined) s += argsv[ea] + " " } console.log(s) }, solidify: function solidify(ary) { for(var i in ary) { if(ary[i] == undefined || ary[i] == '') ary.splice(i,1) } return ary } };
Number.prototype.factorial = function() { if (this <= 1) return 1; var n = this; var sum = n; while(n > 1) sum *= --n; return sum; };