package main
import (
"fmt"
"strings"
)
func findLargestAndSmallestWords(s string) (string, string) {
words := strings.Fields(s)
if len(words) == 0 {
return "", ""
}
largest, smallest := words[0], words[0]
for _, word := range words {
if len(word) > len(largest) {
largest = word
}
if len(word) < len(smallest) {
smallest = word
}
}
return largest, smallest
}
func main() {
s := "Go is statically typed, compiled general purpose programming language"
largest, smallest := findLargestAndSmallestWords(s)
fmt.Printf("Largest word: %s\n", largest)
fmt.Printf("Smallest word: %s\n", smallest)
}
/*
run:
Largest word: programming
Smallest word: Go
*/