Created
April 6, 2014 13:21
-
-
Save willmcneilly/10005941 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
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
// Finding a factorial by iteration. multiply 1 by 2 take the result and multiply by three until we reach n. | |
function factorial(n) { | |
return factIter(1, 1, n); | |
} | |
function factIter(product, counter, maxCount) { | |
if (counter > maxCount) { | |
return product; | |
} | |
else { | |
return factIter(product * counter, counter + 1, maxCount); | |
} | |
} | |
console.log(factorial(4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment