Complete the code to check if the pattern exists in the text using Go's built-in function.
package main import ( "fmt" "strings" ) func main() { text := "hello world" pattern := "world" found := strings.[1](text, pattern) fmt.Println(found) }
The strings.Contains function returns true if the pattern is found in the text.
Complete the code to find the first index of the pattern in the text.
package main import ( "fmt" "strings" ) func main() { text := "golang is fun" pattern := "is" index := strings.[1](text, pattern) fmt.Println(index) }
strings.Index returns the first position of the pattern in the text or -1 if not found.
Fix the error in the code to correctly check if the pattern is at the start of the text.
package main import ( "fmt" "strings" ) func main() { text := "start here" pattern := "start" result := strings.[1](text, pattern) fmt.Println(result) }
strings.HasPrefix checks if the text starts with the given pattern.
Fill both blanks to create a map of words and their lengths for words longer than 3 characters.
package main import "fmt" func main() { words := []string{"go", "code", "play", "fun"} lengths := map[string]int{ [1]: [2], } fmt.Println(lengths) }
Use word as the key and len(word) as the value to map each word to its length.
Fill all three blanks to create a filtered map of words and lengths where length is greater than 3.
package main import "fmt" func main() { words := []string{"go", "code", "play", "fun"} lengths := map[string]int{} for _, [1] := range words { if [2] [3] 3 { lengths[[1]] = len([1]) } } fmt.Println(lengths) }
Loop variable is word. Check if len(word) > 3 to filter words longer than 3 characters.
