/**
 * This function takes two lists as input and returns a new list containing all the elements that are common to both lists.
 *
 * Example:
 * Input: list1 = [1, 2, 3, 4, 5], list2 = [4, 5, 6, 7, 8]
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

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

    // Iterate over each element in list1
    for (element1 in list1) {
        // Iterate over each element in list2
        for (element2 in list2) {
            // Check if the current elements are equal
            if (element1 == element2) {
                // Append the common element to the list
                commonElements.add(element1)
                // Break out of the inner loop and proceed to the next element in list1
                break
            }
        }
    }

    return commonElements
}
/**
 * This function takes two lists as input and returns a new list containing all the elements that are common to both lists.
 *
 * Example:
 * Input: list1 = [1, 2, 3, 4, 5], list2 = [4, 5, 6, 7, 8]
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes two lists as input and returns a new list containing all the elements that are common to both lists.
 *
 * Example:
 * Input: list1 = [1, 2, 3, 4, 5], list2 = [4, 5, 6, 7, 8]
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

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

    // Iterate over each element in list1
    for (element1 in list1) {
        // Iterate over each element in list2
        for (element2 in list2) {
            // Check if the current elements are equal
            if (element1 == element2) {
                // Append the common element to the list
                commonElements.add(element1)
                // Break out of the inner loop and proceed to the next element in list1
                break
            }
        }
    }

    return commonElements
}