/**
 * Given two lists, return a new list containing the common elements found in both lists.
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) ➞ [4, 5]
 *
 * @param list1 First list
 * @param list2 Second list
 * @return A new list containing the common elements
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElementsList = mutableListOf<Int>()

    for (element in list1) {
        if (element in list2) {
            commonElementsList.add(element)
        }
    }

    return commonElementsList
}
/**
 * Given two lists, return a new list containing the common elements found in both lists.
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) ➞ [4, 5]
 *
 * @param list1 First list
 * @param list2 Second list
 * @return A new list containing the common elements
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, return a new list containing the common elements found in both lists.
 *
 * Example:
 * commonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) ➞ [4, 5]
 *
 * @param list1 First list
 * @param list2 Second list
 * @return A new list containing the common elements
 */
fun commonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElementsList = mutableListOf<Int>()

    for (element in list1) {
        if (element in list2) {
            commonElementsList.add(element)
        }
    }

    return commonElementsList
}