Last active
January 21, 2022 19:29
-
-
Save delta48/4d77e270c3d1d6d0603d56c46d6ee6e3 to your computer and use it in GitHub Desktop.
Revisions
-
delta48 revised this gist
Jan 21, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,6 @@ function fib(n) { } function sumFibs(num) { let tmp = []; let nfib = 1; let i = 1; -
delta48 created this gist
Jan 21, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ // solution for // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers const memo = {}; function fib(n) { if (n in memo) return memo[n]; if (n <= 2) return 1; memo[n] = fib(n - 1) + fib(n - 2); return memo[n]; } function sumFibs(num) { if (num == 1) return 1; let tmp = []; let nfib = 1; let i = 1; while (nfib <= num) { if (nfib % 2 === 1) tmp.push(nfib); i++; nfib = fib(i); } return tmp.reduce((a, b) => a + b); } sumFibs(4);