/**
 * This function takes two lists as input and returns a new list
 * containing the intersection of the two lists using list comprehension and looping structures.
 *
 * @param list1 First list containing elements.
 * @param list2 Second list containing elements.
 * @return New list containing the intersection of list1 and list2.
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Use list comprehension to find the common elements between the two lists
    val intersection = list1.filter { num -> list2.any { elem -> num == elem } }
    
    // Remove any duplicates and sort the intersection list in ascending order
    return intersection.toSet().sorted()
}
/**
 * This function takes two lists as input and returns a new list
 * containing the intersection of the two lists using list comprehension and looping structures.
 *
 * @param list1 First list containing elements.
 * @param list2 Second list containing elements.
 * @return New list containing the intersection of list1 and list2.
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes two lists as input and returns a new list
 * containing the intersection of the two lists using list comprehension and looping structures.
 *
 * @param list1 First list containing elements.
 * @param list2 Second list containing elements.
 * @return New list containing the intersection of list1 and list2.
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Use list comprehension to find the common elements between the two lists
    val intersection = list1.filter { num -> list2.any { elem -> num == elem } }
    
    // Remove any duplicates and sort the intersection list in ascending order
    return intersection.toSet().sorted()
}