diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | exercises/anonymous-functions/anonymous-functions1/main.go | 15 | ||||
-rw-r--r-- | exercises/anonymous-functions/anonymous-functions2/main.go | 15 | ||||
-rw-r--r-- | exercises/anonymous-functions/anonymous-functions3/main.go | 35 | ||||
-rw-r--r-- | info.toml | 25 |
5 files changed, 91 insertions, 0 deletions
@@ -1,2 +1,3 @@ dist/ coverage.out +.DS_Store
\ No newline at end of file diff --git a/exercises/anonymous-functions/anonymous-functions1/main.go b/exercises/anonymous-functions/anonymous-functions1/main.go new file mode 100644 index 0000000..20a90cf --- /dev/null +++ b/exercises/anonymous-functions/anonymous-functions1/main.go @@ -0,0 +1,15 @@ +// anonymous functions1 +// Make me compile! + +// I AM NOT DONE +package main + +import "fmt" + +func main() { + + func(name string) { + fmt.Printf("Hello %s", name) + }() + +} diff --git a/exercises/anonymous-functions/anonymous-functions2/main.go b/exercises/anonymous-functions/anonymous-functions2/main.go new file mode 100644 index 0000000..0c899a1 --- /dev/null +++ b/exercises/anonymous-functions/anonymous-functions2/main.go @@ -0,0 +1,15 @@ +// anonymous functions2 +// Make me compile! + +// I AM NOT DONE +package main + +import "fmt" + +func main() { + var sayBye func(name string) + + sayBye = func() { + fmt.Printf("Bye %s", n) + } +} diff --git a/exercises/anonymous-functions/anonymous-functions3/main.go b/exercises/anonymous-functions/anonymous-functions3/main.go new file mode 100644 index 0000000..d49c752 --- /dev/null +++ b/exercises/anonymous-functions/anonymous-functions3/main.go @@ -0,0 +1,35 @@ +// anonymous functions3 +// Make me compile! + +// I AM NOT DONE +package main + +import "fmt" + +func updateStatus() func() string { + var index int + orderStatus := map[int]string{ + 1: "TO DO", + 2: "DOING", + 3: "DONE", + } + + return func() string { + index++ + return "What should I return?" + } +} + +func main() { + anonymous_func := updateStatus() + var status string + + status = anonymous_func() + status = anonymous_func() + + if status == "DONE" { + fmt.Println("Good Job!") + } else { + panic("To complete the challenge the status must be DONE") + } +} @@ -251,3 +251,28 @@ Embedding is achieved using just the struct name. After embedding a struct, we are able to access the fields through the base struct, without having to specify the full path to the field. But you can do if you want. """ + +[[exercises]] +name = "anonymous-functions1" +path = "exercises/anonymous-functions/anonymous-functions1/main.go" +mode = "compile" +hint = """ +The function needs a string to print +""" + +[[exercises]] +name = "anonymous-functions2" +path = "exercises/anonymous-functions/anonymous-functions2/main.go" +mode = "compile" +hint = """ +Maybe you should call the function with a param +""" + +[[exercises]] +name = "anonymous-functions3" +path = "exercises/anonymous-functions/anonymous-functions3/main.go" +mode = "compile" +hint = """ +1 - updateStatus() function should return an orderStatus index like orderStatus[index] +2 - Maybe you should call anonymous_func once more time +"""
\ No newline at end of file |