You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In "if-conditional" for one element statement in Max method change index from 1 to 0 for data.Get(x) ."
Currently your code "As Is" will generate following error for one element condition: panic: runtime error: index out of range
You currently have the following:
func Max(data MaxInterface) (ok bool, max interface{}) {
if data.Len() == 0{
return false, nil //no elements in the collection, no Max value
}
if data.Len() == 1{ //Only one element, return it alongside with true
return true, data.Get(1)
}
max = data.Get(0)//the first element is the max for now
m := 0
for i:=1; i<data.Len(); i++ {
if data.Bigger(i, m){ //we found a bigger value in our slice
max = data.Get(i)
m = i
}
}
return true, max
}
Should be corrected to the following
func Max(data MaxInterface) (ok bool, max interface{}) {
if data.Len() == 0{
return false, nil //no elements in the collection, no Max value
}
if data.Len() == 1{ //Only one element, return it alongside with true
return true, data.Get(0)
}
max = data.Get(0)//the first element is the max for now
m := 0
for i:=1; i<data.Len(); i++ {
if data.Bigger(i, m){ //we found a bigger value in our slice
max = data.Get(i)
m = i
}
}
return true, max
}
The text was updated successfully, but these errors were encountered:
In "if-conditional" for one element statement in Max method change index from 1 to 0 for data.Get(x) ."
Currently your code "As Is" will generate following error for one element condition:
panic: runtime error: index out of range
You currently have the following:
Should be corrected to the following
The text was updated successfully, but these errors were encountered: