Last active
April 3, 2019 17:02
-
-
Save eugenserbanescu/ef2bc1d362f0076a5c2b85ceeb2f139f to your computer and use it in GitHub Desktop.
First stab at Fibonacci
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 fibonacci = (limit, list=[1, 1]) => { | |
const currentIndex = list.length - 1 | |
const newNumber = list[currentIndex - 1] + list[currentIndex] | |
if( newNumber >= limit) { | |
return list | |
} else { | |
return fibonacci(limit, list.concat([newNumber]), currentIndex + 1) | |
} | |
} | |
console.log(fibonacci(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment