well this piece of code is working well, whereas the code i have written for getting maximum marks is not working, can anyone help?
func minMax(array: [Int])->(min:Int, max:Int)?
{
if array.isEmpty
{
return nil
}
var currentMin=array[0]
var currentMax=array[0]
for obj in array[1..<array.count]
{
if obj<currentMin
{
currentMin=obj
}else if obj>currentMax
{
currentMax=obj
}
}
return (currentMin,currentMax)
}
if let bounds=minMax(array:[8, -6, 2, 1,999])
{
print("The minimum value is:\(bounds.min)")
print("The maximum value is:\(bounds.max)")
}
func topperOfClass(array: [Int])->(Topper: Int){
if array.isEmpty
{
return nil
}
else if ((array.count)<1)
{
return nil
}
else if ((array.count)>1)
{
var temp=array[0]
for obj in array[1..<array.count]
{
if obj>temp{
temp=obj
}
}
return temp
}
}
var abc=topperOfClass(array:[20,10,30,49,46,47])
print("The highest marks obtained in class are: ", abc.Topper)
No any search results
You already invited:
1 Answers
JavierPons
Upvotes from:
1. you are trying to return a Tupple with only one element, it’s not possible.
2. I should be like this: