/**
 * This exercise requires finding the common characters between two strings using loops.
 *
 * Write a function that takes two strings as input and returns a list of characters that are present in both strings.
 * The order of characters in the returned list should follow the order in which they appear in the first string.
 *
 * Example:
 * commonChars("hello", "world") should return ['l', 'o']
 *
 * Your task is to complete the code by using loops and without using any built-in Kotlin functions.
 *
 * Hint:
 * - You may use the 'in' operator to check if a character is in a string.
 * - Use a loop to iterate over the characters in the first string and check if each character is present in the second string.
 * - Keep track of the common characters in a separate list and return it at the end.
 *
 * Good luck!
 */
fun commonChars(string1: String, string2: String): List<Char> {

    val commonCharacters = mutableListOf<Char>()

    for (char in string1) {
        if (char in string2 && char !in commonCharacters) {
            commonCharacters.add(char)
        }
    }

    return commonCharacters
}
/**
 * This exercise requires finding the common characters between two strings using loops.
 *
 * Write a function that takes two strings as input and returns a list of characters that are present in both strings.
 * The order of characters in the returned list should follow the order in which they appear in the first string.
 *
 * Example:
 * commonChars("hello", "world") should return ['l', 'o']
 *
 * Your task is to complete the code by using loops and without using any built-in Kotlin functions.
 *
 * Hint:
 * - You may use the 'in' operator to check if a character is in a string.
 * - Use a loop to iterate over the characters in the first string and check if each character is present in the second string.
 * - Keep track of the common characters in a separate list and return it at the end.
 *
 * Good luck!
 */
fun commonChars(string1: String, string2: String): List<Char> {
/**
 * This exercise requires finding the common characters between two strings using loops.
 *
 * Write a function that takes two strings as input and returns a list of characters that are present in both strings.
 * The order of characters in the returned list should follow the order in which they appear in the first string.
 *
 * Example:
 * commonChars("hello", "world") should return ['l', 'o']
 *
 * Your task is to complete the code by using loops and without using any built-in Kotlin functions.
 *
 * Hint:
 * - You may use the 'in' operator to check if a character is in a string.
 * - Use a loop to iterate over the characters in the first string and check if each character is present in the second string.
 * - Keep track of the common characters in a separate list and return it at the end.
 *
 * Good luck!
 */
fun commonChars(string1: String, string2: String): List<Char> {

    val commonCharacters = mutableListOf<Char>()

    for (char in string1) {
        if (char in string2 && char !in commonCharacters) {
            commonCharacters.add(char)
        }
    }

    return commonCharacters
}