function factorial(n) { // debugger; if (Number.isInteger(n) && n > 0) { if (!(n in factorial)) { factorial[n] = n * factorial(n - 1); } console.log('print:',n); return factorial[n]; } else { return NaN; } } factorial[1] = 1; console.log('factorial(6):',factorial(6)); console.log('factorial[5]:',factorial[5]);