Skip to content

Instantly share code, notes, and snippets.

@MikaelFangel
Last active November 28, 2022 10:36
Show Gist options
  • Save MikaelFangel/4a7b894c72a23f040829f80dbfcfc52a to your computer and use it in GitHub Desktop.
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
/**
* 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