/**
 * This function takes in two lists and returns a new list that contains the common elements
 * found in both lists using identity comparison. The function stops searching once it finds
 * the first common element and ignores any duplicates.
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements found in both input lists.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()
    for (element1 in list1) {
        for (element2 in list2) {
            if (element1 === element2) {  // Use identity comparison to check if elements are same object
                if (element1 !in commonElements) {  // Ignore duplicates
                    commonElements.add(element1)
                }
                break  // Stop searching after finding first common element
            }
        }
    }
    return commonElements
}
/**
 * This function takes in two lists and returns a new list that contains the common elements
 * found in both lists using identity comparison. The function stops searching once it finds
 * the first common element and ignores any duplicates.
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements found in both input lists.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * This function takes in two lists and returns a new list that contains the common elements
 * found in both lists using identity comparison. The function stops searching once it finds
 * the first common element and ignores any duplicates.
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements found in both input lists.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()
    for (element1 in list1) {
        for (element2 in list2) {
            if (element1 === element2) {  // Use identity comparison to check if elements are same object
                if (element1 !in commonElements) {  // Ignore duplicates
                    commonElements.add(element1)
                }
                break  // Stop searching after finding first common element
            }
        }
    }
    return commonElements
}