Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created February 4, 2019 03:48
Show Gist options
  • Save stevencurtis/0370e4e55491be1e245c78cacbaabde5 to your computer and use it in GitHub Desktop.
Save stevencurtis/0370e4e55491be1e245c78cacbaabde5 to your computer and use it in GitHub Desktop.
An iterative implementation of the Fibonacci series
func fib (_ n: Int) -> Int {
guard n > 1 else {return n}
var a = 0
var b = 1
for _ in 2...n {
let temp = b
b = a + b
a = temp
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment