/**
 * This exercise requires you to find the intersection of two lists using the 'in' operator and enumerate function.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A new list containing the elements that are common to both list1 and list2
 *
 * Example:
 * intersectionMembershipEnumerate(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun intersectionMembershipEnumerate(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()
    
    // Iterate over the elements of list1 using the 'forEachIndexed' function
    list1.forEachIndexed { index, element ->
        // Check if the element is also present in list2 using the 'in' operator
        if (element in list2) {
            // Append the element to the intersection list
            intersection.add(element)
        }
    }
    
    return intersection
}
/**
 * This exercise requires you to find the intersection of two lists using the 'in' operator and enumerate function.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A new list containing the elements that are common to both list1 and list2
 *
 * Example:
 * intersectionMembershipEnumerate(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun intersectionMembershipEnumerate(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise requires you to find the intersection of two lists using the 'in' operator and enumerate function.
 *
 * @param list1 A list of elements
 * @param list2 Another list of elements
 * @return A new list containing the elements that are common to both list1 and list2
 *
 * Example:
 * intersectionMembershipEnumerate(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun intersectionMembershipEnumerate(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()
    
    // Iterate over the elements of list1 using the 'forEachIndexed' function
    list1.forEachIndexed { index, element ->
        // Check if the element is also present in list2 using the 'in' operator
        if (element in list2) {
            // Append the element to the intersection list
            intersection.add(element)
        }
    }
    
    return intersection
}