Skip to content

Instantly share code, notes, and snippets.

@naughty-code
Created November 7, 2016 21:35
Show Gist options
  • Save naughty-code/ed5f3ecb7daec4bf679ea0c1a32d331f to your computer and use it in GitHub Desktop.
Save naughty-code/ed5f3ecb7daec4bf679ea0c1a32d331f to your computer and use it in GitHub Desktop.
/** 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 = w.toLowerCase.groupBy(char => char).map{
case (char, repetitions) => (char, repetitions.length)
}.toList.sortBy{ case (char, _) => char}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment