I am doing scala course on coursera. I am going through week 6 assignment. I have created a function which finds the occurence of a char in a word. The test method is failing with respect to the expected result sequence.

Here is the problem description: 

```
/** A word is simply a `String`. */
type Word = String
/** Converts the word into its character occurrence list.
*
*  Note: the uppercase and lowercase version of the character are treated as the
*  same character, and are represented as a lowercase character in the occurrence list.
*
*  Note: you must use `groupBy` to implement this method!
*/

def wordOccurrences(w: Word): Occurrences = {

   def breakWord(s: List[Char], xs: List[(Char, Int)]): List[(Char, Int)] = s match {
   case Nil => xs
   case char :: rest =>     breakWord(s.tail, matchTuple(xs, char))
   }

   breakWord(w.toList, List[(Char, Int)]())
}

 def matchTuple(tupleList: List[(Char, Int)], char: Char): List[(Char, Int)] = tupleList match {
 case Nil => tupleList:+ (char.toLower, 1)
 case pair :: restOfList => {
   if(pair._1.toLower == char.toLower)
      restOfList :+(pair._1, pair._2+1)
   else
      tupleList:+ (char.toLower, 1)
  }
}

```

Can someone please point out what I am doing wrong. I do not need a direct answer, just a logical hint as to what is wrong with my sequence. Here is the test and its result: 

```
 assert(wordOccurrences("Robert") === List(('b', 1), ('e', 1), ('o', 1), ('r', 2), ('t', 1)))

```

Here is the output: 

```
[info] - wordOccurrences: Robert *** FAILED ***
[info]   List((o,1), (b,1), (e,1), (r,2), (t,1)) did not equal List((b,1), (e,1), (o,1), (r,2), (t,1)) (AnagramsSuite.scala:20)

```

**Update**:
Refactored my function: 

```
def wordOccurrences(w: Word): Occurrences = {

    def breakWord(s: List[Char], xs: List[(Char, Int)]): List[(Char, Int)] = s match {
      case Nil => xs
      case char :: rest =>     breakWord(s.tail, xs:+ (char, 1))
    }

    breakWord(w.toList, List[(Char, Int)]()).groupBy( pair => pair._1.toLower)
      .map(entry => (entry._1.toLower, (entry._1.toLower, entry._2.size)) )
      .values.toList.sorted
  }

```

It looks too bad, but I will work on to improve this method further.