79223133

Date: 2024-11-25 13:04:11
Score: 1
Natty:
Report link

Here’s the corrected implementation using an iterative approach to compute the factorial:

function factorial(n) {
    if (n === 0 || n === 1) {
        return 1; 
    }

    let result = 1;
    while (n > 1) {
        result *= n; 
        n--;         
    }

    return result; 
}
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: ilius Sagar