Created
February 4, 2019 03:48
-
-
Save stevencurtis/0370e4e55491be1e245c78cacbaabde5 to your computer and use it in GitHub Desktop.
An iterative implementation of the Fibonacci series
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
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