Skip to content

Instantly share code, notes, and snippets.

@banjeremy
Last active July 1, 2017 16:24
Show Gist options
  • Save banjeremy/3a2534a2e54b2bbc3adf2f718cd9b9b3 to your computer and use it in GitHub Desktop.
Save banjeremy/3a2534a2e54b2bbc3adf2f718cd9b9b3 to your computer and use it in GitHub Desktop.
function takes a string and returns a map of characters to frequency
def charFrequency(str: String): Map[Char, Int] = {
var chars = Map[Char, Int]()
for {
c <- str
if c != ' '
} {
chars += (c.toLower -> (chars.getOrElse(c, 0) + 1))
}
chars
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment