/**
 * Write a function that takes a list of words and a string of text as input and counts the number of occurrences
 * of each word in the text. The function should return a map where the keys are the words from the wordList
 * and the corresponding values are the counts of the respective words in the text.
 *
 * @param wordList A list of words to be counted.
 * @param text A string of text to search for occurrences of the words.
 * @return A map where keys are words and values are the counts of the respective words.
 */
fun countWordOccurrences(wordList: List<String>, text: String): Map<String, Int> {

    val wordCount = mutableMapOf<String, Int>()

    for (word in wordList) {
        // Initialize count to 0 for each word
        wordCount[word] = 0
    }

    // Iterate over each word in the list
    for (word in wordList) {
        // Iterate over each word in the text
        for (textWord in text.split(" ")) {
            // Check if the word matches the text word (ignoring case)
            if (word.toLowerCase() == textWord.toLowerCase()) {
                // Increment the count by 1
                wordCount[word] = wordCount[word]!! + 1
            }
        }
    }

    return wordCount
}
/**
 * Write a function that takes a list of words and a string of text as input and counts the number of occurrences
 * of each word in the text. The function should return a map where the keys are the words from the wordList
 * and the corresponding values are the counts of the respective words in the text.
 *
 * @param wordList A list of words to be counted.
 * @param text A string of text to search for occurrences of the words.
 * @return A map where keys are words and values are the counts of the respective words.
 */
fun countWordOccurrences(wordList: List<String>, text: String): Map<String, Int> {
/**
 * Write a function that takes a list of words and a string of text as input and counts the number of occurrences
 * of each word in the text. The function should return a map where the keys are the words from the wordList
 * and the corresponding values are the counts of the respective words in the text.
 *
 * @param wordList A list of words to be counted.
 * @param text A string of text to search for occurrences of the words.
 * @return A map where keys are words and values are the counts of the respective words.
 */
fun countWordOccurrences(wordList: List<String>, text: String): Map<String, Int> {

    val wordCount = mutableMapOf<String, Int>()

    for (word in wordList) {
        // Initialize count to 0 for each word
        wordCount[word] = 0
    }

    // Iterate over each word in the list
    for (word in wordList) {
        // Iterate over each word in the text
        for (textWord in text.split(" ")) {
            // Check if the word matches the text word (ignoring case)
            if (word.toLowerCase() == textWord.toLowerCase()) {
                // Increment the count by 1
                wordCount[word] = wordCount[word]!! + 1
            }
        }
    }

    return wordCount
}