package orderedcount func OrderedCount(text string) []Tuple { if text == "" { return []Tuple{} } var t = make(map[rune]int) for i := 0; i < len(text); i++ { var currentLetter = rune(text[i]) t[currentLetter] +=1; } var response []Tuple var processed = make(map[rune]bool) for i := 0; i < len(text); i++ { var currentRune = rune(text[i]) if !processed[currentRune] { response = append(response, Tuple{Char: currentRune, Count: t[currentRune], }) processed[currentRune] = true } } return response }
- package orderedcount
// Use the preloaded Tuple struct as return type// type Tuple struct {// Char rune// Count int// }- func OrderedCount(text string) []Tuple {
// to implement}- if text == "" {
- return []Tuple{}
- }
- var t = make(map[rune]int)
- for i := 0; i < len(text); i++ {
- var currentLetter = rune(text[i])
- t[currentLetter] +=1;
- }
- var response []Tuple
- var processed = make(map[rune]bool)
- for i := 0; i < len(text); i++ {
- var currentRune = rune(text[i])
- if !processed[currentRune] {
- response = append(response, Tuple{Char: currentRune, Count: t[currentRune], })
- processed[currentRune] = true
- }
- }
- return response
- }