Created
January 19, 2018 22:18
-
-
Save gchriswill/2a3b36c69f2cede12a35d4e73f132927 to your computer and use it in GitHub Desktop.
Swift 4 Extension for finding the biggest integer value from an array of integers
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
extension Array where Element: SignedInteger { | |
static func findMaxInt(arr:[Int]) -> Int{ | |
var previous = Int() | |
var max = Int() | |
arr.forEach { (n) in | |
max = n > previous && n > max ? n : max | |
previous = n; | |
} | |
return max | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment