/**
 * This exercise is designed to test your understanding of accessing elements of a list and identity comparison.
 * You are required to write a function that takes two lists as input and returns a list of elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list of common elements found in both lists.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    for (element in list1) {
        if (element in list2 && element !in commonElements) {
            commonElements.add(element)
        }
    }
    return commonElements
}
/**
 * This exercise is designed to test your understanding of accessing elements of a list and identity comparison.
 * You are required to write a function that takes two lists as input and returns a list of elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list of common elements found in both lists.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise is designed to test your understanding of accessing elements of a list and identity comparison.
 * You are required to write a function that takes two lists as input and returns a list of elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list of common elements found in both lists.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    for (element in list1) {
        if (element in list2 && element !in commonElements) {
            commonElements.add(element)
        }
    }
    return commonElements
}