/**
 * This exercise aims to test your understanding of the intersection of "is not Operator" and its advantages.
 *
 * Write a function that takes two lists as input and returns a new list containing the common elements between the two lists. The returned list should not contain any duplicate elements.
 *
 * You are not allowed to use the built-in intersection method or any external libraries to solve the exercise. You must use the "is not Operator" to check for common elements.
 *
 * Example:
 * list1 = [1, 2, 3, 4, 5]
 * list2 = [4, 5, 6, 7, 8]
 * val commonElements = listCommonElements(list1, list2)
 * println(commonElements)  // Output: [4, 5]
 */
fun listCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (element in list1) {
        if (element != null) {  // Add the condition for checking common elements using the "is not Operator"
            if (element in list2 && element !in commonElements) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}
/**
 * This exercise aims to test your understanding of the intersection of "is not Operator" and its advantages.
 *
 * Write a function that takes two lists as input and returns a new list containing the common elements between the two lists. The returned list should not contain any duplicate elements.
 *
 * You are not allowed to use the built-in intersection method or any external libraries to solve the exercise. You must use the "is not Operator" to check for common elements.
 *
 * Example:
 * list1 = [1, 2, 3, 4, 5]
 * list2 = [4, 5, 6, 7, 8]
 * val commonElements = listCommonElements(list1, list2)
 * println(commonElements)  // Output: [4, 5]
 */
fun listCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise aims to test your understanding of the intersection of "is not Operator" and its advantages.
 *
 * Write a function that takes two lists as input and returns a new list containing the common elements between the two lists. The returned list should not contain any duplicate elements.
 *
 * You are not allowed to use the built-in intersection method or any external libraries to solve the exercise. You must use the "is not Operator" to check for common elements.
 *
 * Example:
 * list1 = [1, 2, 3, 4, 5]
 * list2 = [4, 5, 6, 7, 8]
 * val commonElements = listCommonElements(list1, list2)
 * println(commonElements)  // Output: [4, 5]
 */
fun listCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (element in list1) {
        if (element != null) {  // Add the condition for checking common elements using the "is not Operator"
            if (element in list2 && element !in commonElements) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}