Skip to content

Instantly share code, notes, and snippets.

@nobuh
Created August 7, 2011 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobuh/1130881 to your computer and use it in GitHub Desktop.
Save nobuh/1130881 to your computer and use it in GitHub Desktop.
Test recursive factorial on node.js
// factorial.js for node.js
BD = require("./bigdecimal"); // https://github.com/jhs/bigdecimal.js
ONE = new BD.BigDecimal.ONE;
// Usage : factorial(BD.BigDecimal("number"))
factorial = function (n) {
if (n.compareTo(ONE) == 0) {
return ONE;
} else {
return n.multiply(factorial (n.subtract(ONE)));
}
}
require('repl').start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment