mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-10 15:21:18 +00:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func getFormattedMessages(messages []string, formatter func(string) string) []string {
|
|
formattedMessages := []string{}
|
|
for _, message := range messages {
|
|
formattedMessages = append(formattedMessages, formatter(message))
|
|
}
|
|
return formattedMessages
|
|
}
|
|
|
|
// don't touch below this line
|
|
|
|
func addSignature(message string) string {
|
|
return message + " Kind regards."
|
|
}
|
|
|
|
func addGreeting(message string) string {
|
|
return "Hello! " + message
|
|
}
|
|
|
|
func test(messages []string, formatter func(string) string) {
|
|
defer fmt.Println("====================================")
|
|
formattedMessages := getFormattedMessages(messages, formatter)
|
|
if len(formattedMessages) != len(messages) {
|
|
fmt.Println("The number of messages returned is incorrect.")
|
|
return
|
|
}
|
|
for i, message := range messages {
|
|
formatted := formattedMessages[i]
|
|
fmt.Printf(" * %s -> %s\n", message, formatted)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
test([]string{
|
|
"Thanks for getting back to me.",
|
|
"Great to see you again.",
|
|
"I would love to hang out this weekend.",
|
|
"Got any hot stock tips?",
|
|
}, addSignature)
|
|
test([]string{
|
|
"Thanks for getting back to me.",
|
|
"Great to see you again.",
|
|
"I would love to hang out this weekend.",
|
|
"Got any hot stock tips?",
|
|
}, addGreeting)
|
|
}
|