/**
 * This function takes in two arrays - array1 and array2 - and returns an array
 * containing the elements that are common to both arrays.
 *
 * @param array1 The first array
 * @param array2 The second array
 * @return The array containing the common elements
 * @throws IllegalArgumentException If either 'array1' or 'array2' is empty
 */
fun intersectionArrays(array1: List<Int>, array2: List<Int>): List<Int> {

    if (array1.isEmpty() || array2.isEmpty()) {
        throw IllegalArgumentException("Both arrays must not be empty")
    }

    val commonElements = mutableListOf<Int>()
    for (num in array1) {
        if (num in array2) {
            commonElements.add(num)
        }
    }
    return commonElements
}
/**
 * This function takes in two arrays - array1 and array2 - and returns an array
 * containing the elements that are common to both arrays.
 *
 * @param array1 The first array
 * @param array2 The second array
 * @return The array containing the common elements
 * @throws IllegalArgumentException If either 'array1' or 'array2' is empty
 */
fun intersectionArrays(array1: List<Int>, array2: List<Int>): List<Int> {
/**
 * This function takes in two arrays - array1 and array2 - and returns an array
 * containing the elements that are common to both arrays.
 *
 * @param array1 The first array
 * @param array2 The second array
 * @return The array containing the common elements
 * @throws IllegalArgumentException If either 'array1' or 'array2' is empty
 */
fun intersectionArrays(array1: List<Int>, array2: List<Int>): List<Int> {

    if (array1.isEmpty() || array2.isEmpty()) {
        throw IllegalArgumentException("Both arrays must not be empty")
    }

    val commonElements = mutableListOf<Int>()
    for (num in array1) {
        if (num in array2) {
            commonElements.add(num)
        }
    }
    return commonElements
}