/**
 * Given two lists, return a new list that contains only the elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list with the common elements.
 *
 * Example:
 * listIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7)) // [4, 5]
 * listIntersection(listOf("apple", "banana", "orange"), listOf("banana", "melon", "grape")) // ["banana"]
 */
fun listIntersection(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    for (element in list1) {
        if (element in list2) {
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, return a new list that contains only the elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list with the common elements.
 *
 * Example:
 * listIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7)) // [4, 5]
 * listIntersection(listOf("apple", "banana", "orange"), listOf("banana", "melon", "grape")) // ["banana"]
 */
fun listIntersection(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * Given two lists, return a new list that contains only the elements that are common to both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list with the common elements.
 *
 * Example:
 * listIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7)) // [4, 5]
 * listIntersection(listOf("apple", "banana", "orange"), listOf("banana", "melon", "grape")) // ["banana"]
 */
fun listIntersection(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    for (element in list1) {
        if (element in list2) {
            commonElements.add(element)
        }
    }

    return commonElements
}