Skip to content

Instantly share code, notes, and snippets.

@henvic
Created December 21, 2013 20:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henvic/8074937 to your computer and use it in GitHub Desktop.
Save henvic/8074937 to your computer and use it in GitHub Desktop.
Factorial example
/*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();
/*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