remove: map as sets
This commit is contained in:
35
22-maps/01-english-dict/01-as-a-slice/main.go
Normal file
35
22-maps/01-english-dict/01-as-a-slice/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) != 1 {
|
||||
fmt.Println("[english word] -> [turkish word]")
|
||||
return
|
||||
}
|
||||
query := args[0]
|
||||
|
||||
english := []string{"good", "great", "perfect"}
|
||||
turkish := []string{"iyi", "harika", "mükemmel"}
|
||||
|
||||
// O(n) -> Inefficient: Depends on 'n'.
|
||||
for i, w := range english {
|
||||
if query == w {
|
||||
fmt.Printf("%q means %q\n", w, turkish[i])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%q not found\n", query)
|
||||
}
|
Reference in New Issue
Block a user