/**
 * Given two arrays of integers, return a new array containing only the common elements found in both arrays.
 *
 * @param array1 First array of integers.
 * @param array2 Second array of integers.
 * @return New array containing only the common elements found in both arrays.
 */
fun commonElementsArrays(array1: List<Int>, array2: List<Int>): List<Int> {

    // Initialize an empty list to store common elements
    val commonElements = mutableListOf<Int>()

    // Iterate over each element in array1
    for (num1 in array1) {
        // Check if the element is also present in array2
        if (num1 in array2) {
            // Add the common element to the commonElements list
            commonElements.add(num1)
        }
    }

    // Return the list of common elements
    return commonElements
}
/**
 * Given two arrays of integers, return a new array containing only the common elements found in both arrays.
 *
 * @param array1 First array of integers.
 * @param array2 Second array of integers.
 * @return New array containing only the common elements found in both arrays.
 */
fun commonElementsArrays(array1: List<Int>, array2: List<Int>): List<Int> {
/**
 * Given two arrays of integers, return a new array containing only the common elements found in both arrays.
 *
 * @param array1 First array of integers.
 * @param array2 Second array of integers.
 * @return New array containing only the common elements found in both arrays.
 */
fun commonElementsArrays(array1: List<Int>, array2: List<Int>): List<Int> {

    // Initialize an empty list to store common elements
    val commonElements = mutableListOf<Int>()

    // Iterate over each element in array1
    for (num1 in array1) {
        // Check if the element is also present in array2
        if (num1 in array2) {
            // Add the common element to the commonElements list
            commonElements.add(num1)
        }
    }

    // Return the list of common elements
    return commonElements
}