Last active
August 29, 2015 14:20
-
-
Save fluidsonic/4e81aa2000b7dc62b099 to your computer and use it in GitHub Desktop.
Randomly returns totally wrong values with Swift optimizations (-O) turned on
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
public func optionalMax <T: Comparable>(elements: T? ...) -> T? { | |
var maximumElement: T? | |
for element in elements { | |
if let element = element { | |
if let existingMaximumElement = maximumElement { | |
if element > existingMaximumElement { | |
maximumElement = element | |
} | |
} | |
else { | |
maximumElement = element | |
} | |
} | |
} | |
return maximumElement | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment