Created
August 7, 2011 22:37
-
-
Save nobuh/1130881 to your computer and use it in GitHub Desktop.
Test recursive factorial on node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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