Created
December 21, 2013 20:57
-
-
Save henvic/8074937 to your computer and use it in GitHub Desktop.
Factorial example
This file contains hidden or 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
/*jslint node: true */ | |
module.exports = function () { | |
'use strict'; | |
var math = require('./math'), | |
number; | |
if (!process.argv[2]) { | |
console.log('Use "node factorial-cli.js <number>" to get the factorial'); | |
process.exit(0); | |
} | |
number = process.argv[2]; | |
console.log(math.factorial(number)); | |
}; | |
module.exports(); |
This file contains hidden or 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
/*jslint node: true */ | |
module.exports = (function () { | |
'use strict'; | |
exports.factorial = function (n) { | |
var res = 1; | |
while (n > 1) { | |
res *= n; | |
n -= 1; | |
} | |
return res; | |
}; | |
return exports; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment