Skip to content

Instantly share code, notes, and snippets.

@bflannery
Created December 20, 2016 00:10
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 bflannery/5daef7b2711a53595b82628854de11cd to your computer and use it in GitHub Desktop.
Save bflannery/5daef7b2711a53595b82628854de11cd to your computer and use it in GitHub Desktop.
Factorize a Number
// Return the factorial of the provided integer.
// If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
// Factorials are often represented with the shorthand notation n!
// For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
function factorialize(num) {
var factoredNumber = num;
if (num === 0 || num === 1)
return 1;
while (num > 1) {
num--;
factoredNumber *= num;
}
return factoredNumber;
}
console.log(factorialize(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment