add: array exercises

This commit is contained in:
Inanc Gumus
2018-12-05 15:02:03 +03:00
parent 25c15716b6
commit 91e17cbeb3
27 changed files with 690 additions and 113 deletions

View File

@ -0,0 +1,44 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
"strings"
)
func main() {
books := [4]string{
"Kafka's Revenge",
"Stay Golden",
"Everythingship",
"Kafka's Revenge 2nd Edition",
}
args := os.Args[1:]
if len(args) != 1 {
fmt.Println("Tell me a book title")
return
}
query := strings.ToLower(args[0])
fmt.Println("Search Results:")
var found bool
for _, v := range books {
if strings.Contains(strings.ToLower(v), query) {
fmt.Println("+", v)
found = true
}
}
if !found {
fmt.Printf("We don't have the book: %q\n", query)
}
}