Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Last active December 24, 2019 21:08
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 jbmilgrom/22bfdc2d2b22dc80f892b1830928f08a to your computer and use it in GitHub Desktop.
Save jbmilgrom/22bfdc2d2b22dc80f892b1830928f08a to your computer and use it in GitHub Desktop.
const factorial = n => {
let total = 1;
while (n > 0) {
total = total * n;
n = n - 1;
}
return total;
};
factorial(0); // => 1
factorial(1); // => 1
factorial(2); // => 2
factorial(3); // => 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment