package main

import (
	"fmt"
	"strings"
)

// TODO: declare a type called `replacer` that has the function signature for the second argument to the `replace` function below
type replacer func(string) string

// TODO: update the replace signature to take a `replacer` as the second argument
func replace(s string, r replacer) string {
	var result string
	for _, v := range s {
		result = result + r(string(v))
	}
	return result
}

func main() {
	// Capitalize each letter
	s := replace("go programmers are gophers", func(s string) string {
		return strings.ToUpper(s)
	})
	fmt.Println(s)

	// replace all vowels with the $ sign
	// TODO: Refactor the second argument to be stored as a variable (`r`) and pass in that variable as the second argument
	r := func(s string) string {
		switch s {
		case "a", "e", "i", "o", "u":
			return "$"
		default:
			return s
		}
	}
	s = replace("go programmers are gophers", r)
	fmt.Println(s)
}
