/**
 * This function takes a list of ingredients that a chef has and a list of selected ingredients.
 * It copies the selected ingredients from the chef's ingredients list into a new list and returns it.
 *
 * @param chefList A list of ingredients that the chef has.
 * @param selection A list of selected ingredients that should be copied.
 * @return A new list containing only the selected ingredients from the chef's list.
 *
 * Example:
 * chefList = listOf("carrot", "tomato", "onion", "potato")
 * selection = listOf("onion", "potato")
 * copySelectedItems(chefList, selection)
 * Output: ["onion", "potato"]
 */
fun copySelectedItems(chefList: List<String>, selection: List<String>): List<String> {

    val selectedItems = mutableListOf<String>()
    
    for (ingredient in selection) {
        if (ingredient in chefList) {
            selectedItems.add(ingredient)
        }
    }
    
    return selectedItems
}

val chefList = listOf("carrot", "tomato", "onion", "potato")
val selection = listOf("onion", "potato")

// Copy the selected ingredients from the chef's list into a new list
val selectedIngredients = copySelectedItems(chefList, selection)
/**
 * This function takes a list of ingredients that a chef has and a list of selected ingredients.
 * It copies the selected ingredients from the chef's ingredients list into a new list and returns it.
 *
 * @param chefList A list of ingredients that the chef has.
 * @param selection A list of selected ingredients that should be copied.
 * @return A new list containing only the selected ingredients from the chef's list.
 *
 * Example:
 * chefList = listOf("carrot", "tomato", "onion", "potato")
 * selection = listOf("onion", "potato")
 * copySelectedItems(chefList, selection)
 * Output: ["onion", "potato"]
 */
fun copySelectedItems(chefList: List<String>, selection: List<String>): List<String> {
/**
 * This function takes a list of ingredients that a chef has and a list of selected ingredients.
 * It copies the selected ingredients from the chef's ingredients list into a new list and returns it.
 *
 * @param chefList A list of ingredients that the chef has.
 * @param selection A list of selected ingredients that should be copied.
 * @return A new list containing only the selected ingredients from the chef's list.
 *
 * Example:
 * chefList = listOf("carrot", "tomato", "onion", "potato")
 * selection = listOf("onion", "potato")
 * copySelectedItems(chefList, selection)
 * Output: ["onion", "potato"]
 */
fun copySelectedItems(chefList: List<String>, selection: List<String>): List<String> {

    val selectedItems = mutableListOf<String>()
    
    for (ingredient in selection) {
        if (ingredient in chefList) {
            selectedItems.add(ingredient)
        }
    }
    
    return selectedItems
}

val chefList = listOf("carrot", "tomato", "onion", "potato")
val selection = listOf("onion", "potato")

// Copy the selected ingredients from the chef's list into a new list
val selectedIngredients = copySelectedItems(chefList, selection)