/**
 * This exercise requires the musician to append new instruments to their existing collection and only keeps those that they have played before.
 *
 * @param musician List of instruments the musician currently plays.
 * @param newInstruments List of new instruments to append.
 * @return Updated list of instruments the musician plays, containing only the instruments from the newInstruments list that were previously played.
 */
fun appendNewElementsAndOperator(musician: MutableList<String>, newInstruments: List<String>): List<String> {

    // Add the new instruments to the musician's collection
    musician.addAll(newInstruments)

    // Define a list of instruments the musician has previously played
    val previouslyPlayed = listOf("guitar", "piano", "drums")

    // Filter the musician's collection and keep only the previously played instruments
    return musician.filter { it in previouslyPlayed }
}
/**
 * This exercise requires the musician to append new instruments to their existing collection and only keeps those that they have played before.
 *
 * @param musician List of instruments the musician currently plays.
 * @param newInstruments List of new instruments to append.
 * @return Updated list of instruments the musician plays, containing only the instruments from the newInstruments list that were previously played.
 */
fun appendNewElementsAndOperator(musician: MutableList<String>, newInstruments: List<String>): List<String> {
/**
 * This exercise requires the musician to append new instruments to their existing collection and only keeps those that they have played before.
 *
 * @param musician List of instruments the musician currently plays.
 * @param newInstruments List of new instruments to append.
 * @return Updated list of instruments the musician plays, containing only the instruments from the newInstruments list that were previously played.
 */
fun appendNewElementsAndOperator(musician: MutableList<String>, newInstruments: List<String>): List<String> {

    // Add the new instruments to the musician's collection
    musician.addAll(newInstruments)

    // Define a list of instruments the musician has previously played
    val previouslyPlayed = listOf("guitar", "piano", "drums")

    // Filter the musician's collection and keep only the previously played instruments
    return musician.filter { it in previouslyPlayed }
}