Skip to content

Instantly share code, notes, and snippets.

@eugenserbanescu
Last active April 3, 2019 17:02
Show Gist options
  • Save eugenserbanescu/ef2bc1d362f0076a5c2b85ceeb2f139f to your computer and use it in GitHub Desktop.
Save eugenserbanescu/ef2bc1d362f0076a5c2b85ceeb2f139f to your computer and use it in GitHub Desktop.
First stab at Fibonacci
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