Last active
October 2, 2022 08:28
-
-
Save konami12/2bea27ae811429ead28d1d5cbb0d20bf to your computer and use it in GitHub Desktop.
Demos
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 characters
console.time("Fibonaci recuursivo"); | |
const fibonacci = (value) => { | |
let result = value; | |
if (value > 1) { | |
result = fibonacci(value - 1) + fibonacci(value - 2); | |
} | |
return result; | |
}; | |
fibonacci(1000); | |
console.timeEnd("Fibonaci recuursivo"); | |
console.time("Fibonaci recuursivo"); | |
let memo = []; | |
const fibonacci2 = (value, memo) => { | |
if(memo[value]) return memo[value]; | |
if (value <= 1) { | |
memo[value] = value; | |
return value; | |
} else { | |
let result = fibonacci2(value -1, memo) + fibonacci2(value -2, memo); | |
memo[value] = result; | |
return result; | |
} | |
}; | |
console.log(fibonacci2(1100, [])); | |
console.timeEnd("Fibonaci recuursivo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment