mercredi 31 mars 2021

other text cases for basic function challenge in hackerank

I am trying to solve this hackerrank challenge.The code gives the right solution and passes the basic test case, however, two other test cases fail. I prefer this approach of solving the problem. Please assist me pass the other test cases thanks in advance. Here is my code:

function factorial(n){
    let myNum = n;
    let res;

    if(myNum === n){
        res = myNum * (n -1);
        myNum = n - 1; 
    }

    if(myNum > 0){
        res = res * (myNum - 1);
        myNum --;
    }
    return res;
}

Aucun commentaire:

Enregistrer un commentaire