Ad

The previous code could not compute 0!

Code
Diff
  • 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);
    • }
    • }