The previous code could not compute 0!
function factorial (n) { if (n === 0 || n === 1) { return 1; } else { return n * factorial(n - 1); } }
- function factorial (n) {
if (n === 1) {- if (n === 0 || n === 1) {
- return 1;
- } else {
- return n * factorial(n - 1);
- }
- }
const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("should test for something", function() { assert(factorial(0), 1); assert(factorial(5), 120); assert(factorial(8),40320); assert(factorial(15),1307674368000); }); });
- const chai = require("chai");
- const assert = chai.assert;
- describe("Solution", function() {
- it("should test for something", function() {
- assert(factorial(0), 1);
- assert(factorial(5), 120);
- assert(factorial(8),40320);
- assert(factorial(15),1307674368000);
- });
- });