/**
 * This exercise requires modifying a list of actor names and controlling loops.
 *
 * Complete the function below which takes in an actor's list of names, an old name, and a new name.
 * The function should replace all occurrences of the old name with the new name and return the modified list.
 *
 * Example:
 * val actorNames = mutableListOf("Tom Hanks", "Leonardo DiCaprio", "Tom Hanks", "Brad Pitt", "Meryl Streep")
 * changeCharacterName(actorNames, "Tom Hanks", "Robert Downey Jr.")
 * Output: ["Robert Downey Jr.", "Leonardo DiCaprio", "Robert Downey Jr.", "Brad Pitt", "Meryl Streep"]
 */
fun changeCharacterName(actor: MutableList<String>, oldName: String, newName: String): List<String> {

    for (index in actor.indices) { // Loop through each index of the list
        if (actor[index] == oldName) { // Check if the current name is the same as the oldName
            actor[index] = newName // Replace the oldName with the newName
        }
    }
    return actor // Return the modified list
}
/**
 * This exercise requires modifying a list of actor names and controlling loops.
 *
 * Complete the function below which takes in an actor's list of names, an old name, and a new name.
 * The function should replace all occurrences of the old name with the new name and return the modified list.
 *
 * Example:
 * val actorNames = mutableListOf("Tom Hanks", "Leonardo DiCaprio", "Tom Hanks", "Brad Pitt", "Meryl Streep")
 * changeCharacterName(actorNames, "Tom Hanks", "Robert Downey Jr.")
 * Output: ["Robert Downey Jr.", "Leonardo DiCaprio", "Robert Downey Jr.", "Brad Pitt", "Meryl Streep"]
 */
fun changeCharacterName(actor: MutableList<String>, oldName: String, newName: String): List<String> {
/**
 * This exercise requires modifying a list of actor names and controlling loops.
 *
 * Complete the function below which takes in an actor's list of names, an old name, and a new name.
 * The function should replace all occurrences of the old name with the new name and return the modified list.
 *
 * Example:
 * val actorNames = mutableListOf("Tom Hanks", "Leonardo DiCaprio", "Tom Hanks", "Brad Pitt", "Meryl Streep")
 * changeCharacterName(actorNames, "Tom Hanks", "Robert Downey Jr.")
 * Output: ["Robert Downey Jr.", "Leonardo DiCaprio", "Robert Downey Jr.", "Brad Pitt", "Meryl Streep"]
 */
fun changeCharacterName(actor: MutableList<String>, oldName: String, newName: String): List<String> {

    for (index in actor.indices) { // Loop through each index of the list
        if (actor[index] == oldName) { // Check if the current name is the same as the oldName
            actor[index] = newName // Replace the oldName with the newName
        }
    }
    return actor // Return the modified list
}