Small Word Filter With List

Geoffrey Challen // 2021.9.0

Write a method called smallWordFilter that, given a non-null String containing words separated by single spaces (" "), returns all the words in the original String that are 3 characters or shorter in the same order in which they appeared in the original String, as a List<String>.

For example, given the input "Xyz is the very best cat" you would return the List<String> containing {"Xyz", "is", "the", "cat"}. We have skipped both "very" and "best" because they are longer than 3 characters.

Note that you should not need any import statements, since Lists are built-in to Kotlin and always available.