Given a String?
containing words separated by the " " (space) character, write a method wordLengths
that return a
Map<String, Int>
mapping each word that is contained in the String
to its length.
require
that the passed String?
is not null
.
So, for example, given the String
"Wow that is amazing", you would return a map with four mappings:
"Wow" to 3, "that" to 4, "is" to 2, and "amazing" to 7.
Note that you should not need any import
statements, since List
s are built-in to Kotlin and always available.
Stuck? You may find these lessons helpful: