/**
 * Given a document and a dictionary of words to replace, replace all occurrences of the words in the document
 * with their corresponding values from the dictionary and return the modified document.
 *
 * @param document A document containing words to be replaced.
 * @param wordDict A dictionary of words to replace.
 * @return The modified document with replaced words.
 *
 * Example:
 * replaceWordsInDocument("Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
 *                        mapOf("ipsum" to "replaced", "elit" to "replaced")) ->
 *                        "Lorem replaced dolor sit amet, consectetur adipiscing replaced."
 */
fun replaceWordsInDocument(document: String, wordDict: Map<String, String>): String {

    val words = document.split(" ")  // Split the document into individual words
    val replacedWords = words.map { word -> wordDict[word] ?: word }  // Replace words if they exist in the dictionary
    
    return replacedWords.joinToString(" ")  // Join the modified words back into a document
}
/**
 * Given a document and a dictionary of words to replace, replace all occurrences of the words in the document
 * with their corresponding values from the dictionary and return the modified document.
 *
 * @param document A document containing words to be replaced.
 * @param wordDict A dictionary of words to replace.
 * @return The modified document with replaced words.
 *
 * Example:
 * replaceWordsInDocument("Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
 *                        mapOf("ipsum" to "replaced", "elit" to "replaced")) ->
 *                        "Lorem replaced dolor sit amet, consectetur adipiscing replaced."
 */
fun replaceWordsInDocument(document: String, wordDict: Map<String, String>): String {
/**
 * Given a document and a dictionary of words to replace, replace all occurrences of the words in the document
 * with their corresponding values from the dictionary and return the modified document.
 *
 * @param document A document containing words to be replaced.
 * @param wordDict A dictionary of words to replace.
 * @return The modified document with replaced words.
 *
 * Example:
 * replaceWordsInDocument("Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
 *                        mapOf("ipsum" to "replaced", "elit" to "replaced")) ->
 *                        "Lorem replaced dolor sit amet, consectetur adipiscing replaced."
 */
fun replaceWordsInDocument(document: String, wordDict: Map<String, String>): String {

    val words = document.split(" ")  // Split the document into individual words
    val replacedWords = words.map { word -> wordDict[word] ?: word }  // Replace words if they exist in the dictionary
    
    return replacedWords.joinToString(" ")  // Join the modified words back into a document
}