Ad
Code
Diff
  • package orderedcount
    
    // Use the preloaded Tuple struct as return type
    // type Tuple struct {
    //	Char  rune
    //	Count int
    // }
    
    func OrderedCount(text string) []Tuple {
      tuples := make([]Tuple, 0)
     for _, c := range text {
         exists := false
         for _, t := range tuples {
           if(t.Char == rune(c)) {
             exists = true
           }
         }
         if (!exists) {
           tuples = append(tuples, Tuple{rune(c), 0})
         }
     }
     for _, c := range text {
         for i := range tuples {
           if(tuples[i].Char == rune(c)) {
             tuples[i].Count++
           }
         }
     }
     return tuples
    }
    • package orderedcount
    • // Use the preloaded Tuple struct as return type
    • // type Tuple struct {
    • // Char rune
    • // Count int
    • // }
    • func OrderedCount(text string) []Tuple {
    • // to implement
    • tuples := make([]Tuple, 0)
    • for _, c := range text {
    • exists := false
    • for _, t := range tuples {
    • if(t.Char == rune(c)) {
    • exists = true
    • }
    • }
    • if (!exists) {
    • tuples = append(tuples, Tuple{rune(c), 0})
    • }
    • }
    • for _, c := range text {
    • for i := range tuples {
    • if(tuples[i].Char == rune(c)) {
    • tuples[i].Count++
    • }
    • }
    • }
    • return tuples
    • }