/**
 * This exercise requires finding the common letters between two words.
 *
 * Given two words as input (word1 and word2), complete the code to return a new string
 * containing the common letters found in both words.
 *
 * Example:
 * findCommonLetters("physical", "therapist")
 * Output: "tis"
 *
 * Note:
 * - The returned string should only contain the letters that are present in both words.
 * - Case sensitivity should be ignored, so "t" and "T" are considered the same letter.
 * - The order of the letters in the returned string doesn't matter.
 */
fun findCommonLetters(word1: String, word2: String): String {

    var commonLetters = ""

    // Convert both words to lowercase for case insensitivity
    val lowerWord1 = word1.toLowerCase()
    val lowerWord2 = word2.toLowerCase()

    // Iterate over each character in word1
    for (letter in lowerWord1) {
        // Check if the letter is present in both word1 and word2
        if (letter in lowerWord2 && letter !in commonLetters) {
            commonLetters += letter
        }
    }

    return commonLetters
}
/**
 * This exercise requires finding the common letters between two words.
 *
 * Given two words as input (word1 and word2), complete the code to return a new string
 * containing the common letters found in both words.
 *
 * Example:
 * findCommonLetters("physical", "therapist")
 * Output: "tis"
 *
 * Note:
 * - The returned string should only contain the letters that are present in both words.
 * - Case sensitivity should be ignored, so "t" and "T" are considered the same letter.
 * - The order of the letters in the returned string doesn't matter.
 */
fun findCommonLetters(word1: String, word2: String): String {
/**
 * This exercise requires finding the common letters between two words.
 *
 * Given two words as input (word1 and word2), complete the code to return a new string
 * containing the common letters found in both words.
 *
 * Example:
 * findCommonLetters("physical", "therapist")
 * Output: "tis"
 *
 * Note:
 * - The returned string should only contain the letters that are present in both words.
 * - Case sensitivity should be ignored, so "t" and "T" are considered the same letter.
 * - The order of the letters in the returned string doesn't matter.
 */
fun findCommonLetters(word1: String, word2: String): String {

    var commonLetters = ""

    // Convert both words to lowercase for case insensitivity
    val lowerWord1 = word1.toLowerCase()
    val lowerWord2 = word2.toLowerCase()

    // Iterate over each character in word1
    for (letter in lowerWord1) {
        // Check if the letter is present in both word1 and word2
        if (letter in lowerWord2 && letter !in commonLetters) {
            commonLetters += letter
        }
    }

    return commonLetters
}