/**
 * Given a list of words and a selection range, this function returns the word occurring at the intersection of the selection and negative indexing.
 *
 * @param wordList A list of words.
 * @param selection A pair containing the start and end index of the selection range.
 * @return The word occurring at the intersection of the selection and negative indexing.
 *
 * Example:
 * val wordList = listOf("fire", "water", "earth", "wind", "lightning")
 * val selection = Pair(1, -2)
 * getWordFromSelection(wordList, selection) => "water"
 */
fun getWordFromSelection(wordList: List<String>, selection: Pair<Int, Int>): String {

    var (startIndex, endIndex) = selection

    // Ensure start index is within bounds
    startIndex = maxOf(startIndex, -wordList.size)

    // Ensure end index is within bounds
    endIndex = minOf(endIndex, -1)

    // Get the word at the intersection of selection and negative indexing
    val selectedWord = wordList.subList(startIndex, endIndex + 1).last()

    return selectedWord
}
/**
 * Given a list of words and a selection range, this function returns the word occurring at the intersection of the selection and negative indexing.
 *
 * @param wordList A list of words.
 * @param selection A pair containing the start and end index of the selection range.
 * @return The word occurring at the intersection of the selection and negative indexing.
 *
 * Example:
 * val wordList = listOf("fire", "water", "earth", "wind", "lightning")
 * val selection = Pair(1, -2)
 * getWordFromSelection(wordList, selection) => "water"
 */
fun getWordFromSelection(wordList: List<String>, selection: Pair<Int, Int>): String {
/**
 * Given a list of words and a selection range, this function returns the word occurring at the intersection of the selection and negative indexing.
 *
 * @param wordList A list of words.
 * @param selection A pair containing the start and end index of the selection range.
 * @return The word occurring at the intersection of the selection and negative indexing.
 *
 * Example:
 * val wordList = listOf("fire", "water", "earth", "wind", "lightning")
 * val selection = Pair(1, -2)
 * getWordFromSelection(wordList, selection) => "water"
 */
fun getWordFromSelection(wordList: List<String>, selection: Pair<Int, Int>): String {

    var (startIndex, endIndex) = selection

    // Ensure start index is within bounds
    startIndex = maxOf(startIndex, -wordList.size)

    // Ensure end index is within bounds
    endIndex = minOf(endIndex, -1)

    // Get the word at the intersection of selection and negative indexing
    val selectedWord = wordList.subList(startIndex, endIndex + 1).last()

    return selectedWord
}