Last active
November 28, 2022 10:36
-
-
Save MikaelFangel/4a7b894c72a23f040829f80dbfcfc52a to your computer and use it in GitHub Desktop.
Get the indexes of all letters in a given word as a list of integers
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
/** | |
* Searches for all indexes of a given character in a word. The search is not case sensitive. | |
* @param c the char to search for | |
* @param word the word to look in | |
* @return list with indexes where the char matches | |
*/ | |
fun getIndexesOfLetters(c: Char, word: String): List<Int> { | |
return word | |
.lowercase() | |
.withIndex() | |
.filter { it.value == c } | |
.map { it.index } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment