/**
 * This function takes a list of taboo words and a text as input and returns the common words found in both.
 *
 * @param tabooWords A list of words considered unacceptable or offensive.
 * @param text The text input to search for common words.
 * @return A list of common words found in both the taboo words list and the text.
 */
fun findIntersection(tabooWords: List<String>, text: String): List<String> {

    val commonWords = mutableListOf<String>()

    // Split the given text into individual words
    val words = text.split(" ")

    // Loop through each word in the tabooWords list
    for (tabooWord in tabooWords) {
        // Check if the tabooWord exists in the words list, ignoring case sensitivity
        if (tabooWord.toLowerCase() in words.map { it.toLowerCase() }) {
            // Check if the tabooWord exists in the commonWords list, ignoring case sensitivity
            if (tabooWord.toLowerCase() !in commonWords.map { it.toLowerCase() }) {
                // Append the tabooWord to the commonWords list
                commonWords.add(tabooWord.toLowerCase())
            }
        }
    }

    return commonWords
}

val tabooWords = listOf("culture", "history", "language", "tradition")
val text = "Exploring the rich cultural history and diverse traditions of different societies."

val commonWords = findIntersection(tabooWords, text)
/**
 * This function takes a list of taboo words and a text as input and returns the common words found in both.
 *
 * @param tabooWords A list of words considered unacceptable or offensive.
 * @param text The text input to search for common words.
 * @return A list of common words found in both the taboo words list and the text.
 */
fun findIntersection(tabooWords: List<String>, text: String): List<String> {
/**
 * This function takes a list of taboo words and a text as input and returns the common words found in both.
 *
 * @param tabooWords A list of words considered unacceptable or offensive.
 * @param text The text input to search for common words.
 * @return A list of common words found in both the taboo words list and the text.
 */
fun findIntersection(tabooWords: List<String>, text: String): List<String> {

    val commonWords = mutableListOf<String>()

    // Split the given text into individual words
    val words = text.split(" ")

    // Loop through each word in the tabooWords list
    for (tabooWord in tabooWords) {
        // Check if the tabooWord exists in the words list, ignoring case sensitivity
        if (tabooWord.toLowerCase() in words.map { it.toLowerCase() }) {
            // Check if the tabooWord exists in the commonWords list, ignoring case sensitivity
            if (tabooWord.toLowerCase() !in commonWords.map { it.toLowerCase() }) {
                // Append the tabooWord to the commonWords list
                commonWords.add(tabooWord.toLowerCase())
            }
        }
    }

    return commonWords
}

val tabooWords = listOf("culture", "history", "language", "tradition")
val text = "Exploring the rich cultural history and diverse traditions of different societies."

val commonWords = findIntersection(tabooWords, text)