/**
 * Write a function that takes in two lists and returns a new list containing only the elements that are common to both lists.
 * The common elements should be in the same order as they appear in the first list.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) should return [4, 5]
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val common = mutableListOf<Int>()

    list1.forEach { element ->
        if (element in list2) {
            common.add(element)
        }
    }

    return common
}
/**
 * Write a function that takes in two lists and returns a new list containing only the elements that are common to both lists.
 * The common elements should be in the same order as they appear in the first list.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) should return [4, 5]
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Write a function that takes in two lists and returns a new list containing only the elements that are common to both lists.
 * The common elements should be in the same order as they appear in the first list.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) should return [4, 5]
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val common = mutableListOf<Int>()

    list1.forEach { element ->
        if (element in list2) {
            common.add(element)
        }
    }

    return common
}