From 5abce6adaf45736528a1e1447150778e4caeebbc Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Thu, 15 Nov 2018 22:38:08 +0300 Subject: [PATCH] add: experimental maps example --- 17-maps/_experimental/main.go | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 17-maps/_experimental/main.go diff --git a/17-maps/_experimental/main.go b/17-maps/_experimental/main.go new file mode 100644 index 0000000..12f580d --- /dev/null +++ b/17-maps/_experimental/main.go @@ -0,0 +1,36 @@ +// 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/ +// + +// why maps instead of keyed arrays etc? +// 120k elements! + +package main + +import ( + "fmt" + "os" + "unicode/utf8" +) + +func main() { + args := os.Args[1:] + if len(args) != 1 { + fmt.Println("[emoji]") + return + } + + moods := [...]string{ + '😊': "a happy", + '😟': "a worried", + '😎': "an awesome", + '😞': "a sad", + '😩': "a crying", + } + + emoji, _ := utf8.DecodeRune([]byte(args[0])) + fmt.Printf("%s is %s emoji\n", args[0], moods[emoji]) +}