/**
 * Given a set of articles and a set of keywords,
 * this function returns the common words present in all articles
 * that match the given keywords.
 *
 * @param articles A set of articles as strings
 * @param keywords A set of keywords as strings
 * @return A set of common words found in the articles that match the keywords
 */
fun findCommonWords(articles: Set<String>, keywords: Set<String>): Set<String> {

    val commonWords = mutableSetOf<String>()

    for (article in articles) {
        val words = article.split(" ").toSet()

        for (keyword in keywords) {
            if (keyword in words) {
                commonWords.add(keyword)
            }
        }
    }

    return commonWords
}

val articles = setOf(
    "Journalism ethics and the digital age",
    "Investigative journalism in the modern era",
    "The role of journalism in society",
    "Fake news: Misinformation in the media",
    "Journalists' responsibility to the truth"
)

val keywords = setOf(
    "journalism",
    "ethics",
    "media",
    "digital",
    "fake news",
    "responsibility",
    "investigative",
    "society"
)

val result = findCommonWords(articles, keywords)
/**
 * Given a set of articles and a set of keywords,
 * this function returns the common words present in all articles
 * that match the given keywords.
 *
 * @param articles A set of articles as strings
 * @param keywords A set of keywords as strings
 * @return A set of common words found in the articles that match the keywords
 */
fun findCommonWords(articles: Set<String>, keywords: Set<String>): Set<String> {
/**
 * Given a set of articles and a set of keywords,
 * this function returns the common words present in all articles
 * that match the given keywords.
 *
 * @param articles A set of articles as strings
 * @param keywords A set of keywords as strings
 * @return A set of common words found in the articles that match the keywords
 */
fun findCommonWords(articles: Set<String>, keywords: Set<String>): Set<String> {

    val commonWords = mutableSetOf<String>()

    for (article in articles) {
        val words = article.split(" ").toSet()

        for (keyword in keywords) {
            if (keyword in words) {
                commonWords.add(keyword)
            }
        }
    }

    return commonWords
}

val articles = setOf(
    "Journalism ethics and the digital age",
    "Investigative journalism in the modern era",
    "The role of journalism in society",
    "Fake news: Misinformation in the media",
    "Journalists' responsibility to the truth"
)

val keywords = setOf(
    "journalism",
    "ethics",
    "media",
    "digital",
    "fake news",
    "responsibility",
    "investigative",
    "society"
)

val result = findCommonWords(articles, keywords)