/**
 * Given a piece of text and a list of words, this function finds and returns the first word in the list that occurs in the text.
 *
 * @param text The piece of text to search for matching words.
 * @param wordList The list of words to find a match in the text.
 * @return The first word from wordList that occurs in the text. Returns null if no matches are found.
 */
fun findMatchingWord(text: String, wordList: List<String>): String? {

    for (word in wordList) {
        for (i in 0 until text.length - word.length + 1) {
            var match = true
            for (j in word.indices) {
                if (text[i + j] != word[j]) {
                    match = false
                    break
                }
            }
            if (match) {
                return word
            }
        }
    }
    return null
}

// Example usage
/**
 * Given a piece of text and a list of words, this function finds and returns the first word in the list that occurs in the text.
 *
 * @param text The piece of text to search for matching words.
 * @param wordList The list of words to find a match in the text.
 * @return The first word from wordList that occurs in the text. Returns null if no matches are found.
 */
fun findMatchingWord(text: String, wordList: List<String>): String? {
/**
 * Given a piece of text and a list of words, this function finds and returns the first word in the list that occurs in the text.
 *
 * @param text The piece of text to search for matching words.
 * @param wordList The list of words to find a match in the text.
 * @return The first word from wordList that occurs in the text. Returns null if no matches are found.
 */
fun findMatchingWord(text: String, wordList: List<String>): String? {

    for (word in wordList) {
        for (i in 0 until text.length - word.length + 1) {
            var match = true
            for (j in word.indices) {
                if (text[i + j] != word[j]) {
                    match = false
                    break
                }
            }
            if (match) {
                return word
            }
        }
    }
    return null
}

// Example usage