Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 536 Bytes

goat-latin.md

File metadata and controls

35 lines (27 loc) · 536 Bytes

Code

func isVowel(s string) bool {
	letter := strings.ToLower(string(s[0]))

	switch letter {
	case "a", "e", "i", "o", "u":
		return true
	}

	return false
}

func toGoatLatin(S string) string {
	words := strings.Split(S, " ")
	solution := ""

	for i, word := range words {
		a := strings.Repeat("a", i+1)
		goatWord := ""

		if isVowel(word) {
			goatWord = word + "ma"
		} else {
			goatWord = word[1:] + string(word[0]) + "ma"
		}

		solution = solution + goatWord + a + " "
	}

	return solution[:len(solution)-1]
}