Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript factorial stack

function factorial(n) {
    let s = new Stack();
    while (n>1){
        s.push(n--);
    }
    let product = 1;
    while (s.length() > 0) {
        product *= s.pop();
    }
    return product;
}
 
PREVIOUS NEXT
Tagged: #javascript #factorial #stack
ADD COMMENT
Topic
Name
8+3 =