function fact(n) {
    const memo = new Map()
    
    if (n < 0) return undefined
    if (n < 2) return 1
    
    if (!memo.has(n)) { 
        memo.set(n, n * fact(n-1))
    }

    return memo.get(n)
}

for (let i=0; i<10; i++) {
    console.log(`${i}! = ${fact(i)}`)
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: