Created
July 4, 2016 20:40
-
-
Save leandroh/78e6c52c0267ac846be8f3e2b04d9c46 to your computer and use it in GitHub Desktop.
Test recursive factorial function in JavaScript.
This file contains hidden or 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
const assert = require('assert'); | |
function factorial(n) { | |
if (n > 1) { | |
return n * factorial(n - 1); | |
} | |
return 1; | |
} | |
assert.equal(factorial(1), 1); | |
assert.equal(factorial(2), 2); | |
assert.equal(factorial(3), 6); | |
assert.equal(factorial(4), 24); | |
assert.equal(factorial(5), 120); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment