Skip to content

Instantly share code, notes, and snippets.

@willmcneilly
Created April 6, 2014 13:21
Show Gist options
  • Save willmcneilly/10005941 to your computer and use it in GitHub Desktop.
Save willmcneilly/10005941 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
// 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