Qtr No. 213, New Town Yehlanka Indore 454775
What will be the output in the following code snippet?
package main
import "fmt"
func compareString[T any](function func(T, T) T, slice []T) T {
result := slice[0]
for index := 1; index < len(slice); index++ {
result = function(result, slice[index])
}
return result
}
func main() {
stringSlice := []string{"Famous Five", "Hardy Boys", "Nancy Drew"}
modifyFunc := func(value1, value2 string) string {
if len(value2) > len(value1) {
return value2
} else {
return value1
}
}
result := compareString(modifyFunc, stringSlice)
fmt.Println(result)
}
Famous Five
Nancy Drew
Hardy Boys
Compilation Error
To get all Go Programming Language - Assessment Exam questions Join Group https://bit.ly/infy_premium_group
We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.
Qtr No. 213, New Town Yehlanka Indore 454775
admin@prepflix.in