From 6d055c59dda4aaa1a277d5610e609700914a4464 Mon Sep 17 00:00:00 2001 From: kanna Date: Mon, 15 Feb 2021 16:21:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A1=E3=83=A2=E5=8C=96=E3=81=AB=E3=82=88?= =?UTF-8?q?=E3=82=8B=E3=82=A2=E3=83=AB=E3=82=B4=E3=83=AA=E3=82=BA=E3=83=A0?= =?UTF-8?q?=E3=81=AE=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app.js b/app.js index ad9a93a7..8b830c5c 100644 --- a/app.js +++ b/app.js @@ -1 +1,16 @@ 'use strict'; +const memo = new Map(); +memo.set(0, 0); +memo.set(1, 1); +function fib(n) { + if(memo.has(n)) { + return memo.get(n); + } + const value = fib(n - 1) + fib(n - 2); + memo.set(n, value); + return value; +} +const length = 40; +for (let i = 0; i <= length; i++) { + console.log(fib(i)); +} \ No newline at end of file