aboutsummaryrefslogtreecommitdiff
path: root/entries/kevindhir/ts/fib.ts
diff options
context:
space:
mode:
authorbraxtonhall2022-10-26 17:24:40 +0000
committerbraxtonhall2022-10-26 17:24:40 +0000
commit460aaa31a61696c01af80402754c66fb732f7a3b (patch)
tree5cd8c64b9f63941bd30601363352aed32bcdce47 /entries/kevindhir/ts/fib.ts
parent01dbd3f3f0829f9bf33bd0c3f152a160218bf09d (diff)
Add Kevin Dhir
Diffstat (limited to 'entries/kevindhir/ts/fib.ts')
-rw-r--r--entries/kevindhir/ts/fib.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/entries/kevindhir/ts/fib.ts b/entries/kevindhir/ts/fib.ts
new file mode 100644
index 0000000..f126a8b
--- /dev/null
+++ b/entries/kevindhir/ts/fib.ts
@@ -0,0 +1,8 @@
+let memo = {1: 1};
+
+function fib(n: number): number {
+ if(n <= 0) return 0;
+ if(memo[n]) return memo[n];
+ memo[n] = fib(n-1) + fib(n-2);
+ return memo[n];
+};