/**
 * This function takes in two lists as arguments and returns a new list containing the common elements
 * between the two lists.
 *
 * @param list1 First list of elements
 * @param list2 Second list of elements
 * @return New list containing common elements between list1 and list2
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

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

    // Loop through each element in list1
    for (element in list1) {
        // Check if the element is also present in list2
        if (element in list2) {
            // Append the common element to the common list
            common.add(element)
        }
    }

    // Return the resulting common list
    return common
}

// Sample inputs
val list1 = listOf(1, 2, 3, 4, 5)
val list2 = listOf(4, 5, 6, 7, 8)
/**
 * This function takes in two lists as arguments and returns a new list containing the common elements
 * between the two lists.
 *
 * @param list1 First list of elements
 * @param list2 Second list of elements
 * @return New list containing common elements between list1 and list2
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes in two lists as arguments and returns a new list containing the common elements
 * between the two lists.
 *
 * @param list1 First list of elements
 * @param list2 Second list of elements
 * @return New list containing common elements between list1 and list2
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

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

    // Loop through each element in list1
    for (element in list1) {
        // Check if the element is also present in list2
        if (element in list2) {
            // Append the common element to the common list
            common.add(element)
        }
    }

    // Return the resulting common list
    return common
}

// Sample inputs
val list1 = listOf(1, 2, 3, 4, 5)
val list2 = listOf(4, 5, 6, 7, 8)