Last active
August 23, 2024 14:43
-
-
Save Hoyasumii/16242b1b3e81a77dd87b94d11bdc7c25 to your computer and use it in GitHub Desktop.
Fibonacci Sequence for JavaScript using Recursion
This file contains 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
const fib = (laps, oldNumber = 1, oldestNumber = 0) => { | |
if (laps === 0) return oldestNumber; | |
if (laps === 1) return oldNumber; | |
const sum = BigInt(oldNumber) + BigInt(oldestNumber); | |
return fib(laps - 1, sum, oldNumber); | |
}; | |
console.time("res"); | |
console.log(fib(1_000_000)) | |
console.timeEnd("res"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment