Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Created March 2, 2021 11:46
Show Gist options
  • Select an option

  • Save bogoreh/f42489beba3791b4bb561389ba66dde5 to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/f42489beba3791b4bb561389ba66dde5 to your computer and use it in GitHub Desktop.
var factorial = function(n) {
var result = 1;
for (var i = 1; i <= n; i++){
result = result * i;
}
return result;
};
println("The value of 5! should be " + 5*4*3*2*1);
println("The value of 5! is " + factorial(5));
println("The value of 0! should be 1");
println("The value of 0! is " + factorial(0));
Program.assertEqual(factorial(5), 120);
Program.assertEqual(factorial(0), 1);
Program.assertEqual(factorial(2), 2);
Program.assertEqual(factorial(4), 24);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment