function jc(num) { let result = [0, 1, 2] function calc(num) { if (num < 2) { return result[num] } if (result[num]) { return result[num] } result[num] = num * calc(num - 1) console.log(result) return result[num] } return calc(num) } console.log(jc(5))