Create a method countLetters
.
countLetters
accepts an array of String
s and returns a Map
from String
s to Int
s.
The map should contain counts of the passed Strings
based on their first letter.
For example, provided the array {"test", "me", "testing"} your Map
should be {"t": 2, "m": 1}.
You should ignore empty String
s and not include any zero counts.
As a reminder, you can retrieve the first character of a String
as a char
using index notation: example[0]
.
You may find substring
more helpful.
You may also want to utilize the Elvis operator ?:
for retrieving a default value from a map when the requested
key does not exist.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: