Skip to content

Instantly share code, notes, and snippets.

@konami12
Last active October 2, 2022 08:28
Show Gist options
  • Save konami12/2bea27ae811429ead28d1d5cbb0d20bf to your computer and use it in GitHub Desktop.
Save konami12/2bea27ae811429ead28d1d5cbb0d20bf to your computer and use it in GitHub Desktop.
Demos
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