/**
 * This exercise aims to find the common words across a set of articles.
 * You need to complete the code by using looping structures and sets.
 *
 * @param articles A list of strings representing articles.
 * @return A set containing all the common words found in the articles.
 */
fun findCommonWords(articles: List<String>): Set<String> {

    // Initialize an empty set to store the common words
    val commonWords = mutableSetOf<String>()

    // Loop through each article
    for ((index, article) in articles.withIndex()) {
        // Split the article into individual words
        val words = article.split(" ")

        // If it's the first article, add all words to the common words set
        if (index == 0) {
            commonWords.addAll(words)
        } else {
            // Create a temporary set to store the words in the current article
            val currentWords = words.toSet()

            // Intersect the temporary set with the common words set
            commonWords.retainAll(currentWords)
        }
    }

    return commonWords
}
/**
 * This exercise aims to find the common words across a set of articles.
 * You need to complete the code by using looping structures and sets.
 *
 * @param articles A list of strings representing articles.
 * @return A set containing all the common words found in the articles.
 */
fun findCommonWords(articles: List<String>): Set<String> {
/**
 * This exercise aims to find the common words across a set of articles.
 * You need to complete the code by using looping structures and sets.
 *
 * @param articles A list of strings representing articles.
 * @return A set containing all the common words found in the articles.
 */
fun findCommonWords(articles: List<String>): Set<String> {

    // Initialize an empty set to store the common words
    val commonWords = mutableSetOf<String>()

    // Loop through each article
    for ((index, article) in articles.withIndex()) {
        // Split the article into individual words
        val words = article.split(" ")

        // If it's the first article, add all words to the common words set
        if (index == 0) {
            commonWords.addAll(words)
        } else {
            // Create a temporary set to store the words in the current article
            val currentWords = words.toSet()

            // Intersect the temporary set with the common words set
            commonWords.retainAll(currentWords)
        }
    }

    return commonWords
}