Last active
July 1, 2017 16:24
-
-
Save banjeremy/3a2534a2e54b2bbc3adf2f718cd9b9b3 to your computer and use it in GitHub Desktop.
function takes a string and returns a map of characters to frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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