let array = [1,5, 10, 2, 20, 9, 3]
let maximumNumber = array.reduce(Int.min, { max($0, $1)})
print(maximumNumber)
This is my code but I need the Maximum value of an Array without any predefined functions and HigherOrder Functions.
>Solution :
func findMaxNumber(inArray : [Int]) -> Int?{
var max = inArray.first
if inArray.isEmpty == false{
for i in 0..<inArray.count{
let x = inArray[i]
if x > max! {
max = x
}
}
}
return max
}
Usage let maxNumber = findMaxNumber(inArray: yourIntArray)