From af039f80b9fc95f7404ca00ca62565d26120e809 Mon Sep 17 00:00:00 2001 From: Taku Mizumoto Date: Sat, 8 Jan 2022 08:29:45 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=88=E3=83=AA=E3=83=9C=E3=83=8A=E3=83=83?= =?UTF-8?q?=E3=83=81=E6=95=B0=E5=88=97=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index bba68419..0f6c8f0e 100644 --- a/app.js +++ b/app.js @@ -1,16 +1,17 @@ 'use strict'; const memo = new Map(); memo.set(0, 0); -memo.set(1, 1); -function trib(n) { +memo.set(1, 0); +memo.set(2, 1); +function fib(n) { if (memo.has(n)) { return memo.get(n); } - const value = trib(n - 1) + trib(n - 2); + const value = fib(n - 1) + fib(n - 2) + fib(n - 3); memo.set(n, value); return value; } const length = 40; for (let i = 0; i <= length; i++) { - console.log(trib(i)); -} + console.log(fib(i)); +} \ No newline at end of file