I have a `List<String>` like so: { "Hello", ...
# announcements
l
I have a
List<String>
like so: { "Hello", "ABC", "yo", "This is", "There are", "An App", "Hey", Help" } I have a
query : String = "Hl"
in Kotlin, how would I construct a filter such that the output is: { "Hello", Help" } If I have to implement the algorithm, what would be a good one? Or is the only way to do so is to loop through each char in the query string? Secondly, if the query is
query : String = "a"
, and let's say the output is { "ABC", "There are", "An App"} I would like to sort this list based on the first index of
query
, e.g: { "ABC", "An App", "There are"} How should I do so in Kotlin? My attempt:
Copy code
val listOfFilteredString = listOfString
                .filter { s-> s.contains(query, ignoreCase = true) }
                .sortedWith(compareBy { s -> s.label.indexOf(query) })
It's not working 😕