Skip to content

Instantly share code, notes, and snippets.

@mahmmad-khamar-shaikh
Last active September 9, 2023 12:28
Memoized-fibonacci-with
function fibonacciWithMemoization(num, cachedResult = []) {
if (cachedResult[num] != null) {
return cachedResult[num];
}
let result;
if (num <= 2) {
result = 1;
} else {
result = fibonacciWithMemoization(num - 1, cachedResult) + fibonacciWithMemoization(num - 2, cachedResult);
}
cachedResult[num] = result;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment