Created
December 20, 2016 00:10
-
-
Save bflannery/5daef7b2711a53595b82628854de11cd to your computer and use it in GitHub Desktop.
Factorize a Number
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
// 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