/**
 * Given two lists of animals, return a new list containing the animals that are common to both lists.
 *
 * @param animals1 The first list of animals
 * @param animals2 The second list of animals
 * @return A list containing the animals that are common to both lists
 *
 * Example:
 * animals1 = listOf("elephant", "giraffe", "lion", "rhino")
 * animals2 = listOf("lion", "zebra", "elephant")
 * getCommonAnimals(animals1, animals2) // Output: ["lion", "elephant"]
 */
fun getCommonAnimals(animals1: List<String>, animals2: List<String>): List<String> {

    val commonAnimals = mutableListOf<String>()

    // Iterate over each animal in the first list
    for (animal in animals1) {
        // Check if the animal is in the second list
        if (animal in animals2) {
            // Append the animal to the common animals list
            commonAnimals.add(animal)
        }
    }

    return commonAnimals
}
/**
 * Given two lists of animals, return a new list containing the animals that are common to both lists.
 *
 * @param animals1 The first list of animals
 * @param animals2 The second list of animals
 * @return A list containing the animals that are common to both lists
 *
 * Example:
 * animals1 = listOf("elephant", "giraffe", "lion", "rhino")
 * animals2 = listOf("lion", "zebra", "elephant")
 * getCommonAnimals(animals1, animals2) // Output: ["lion", "elephant"]
 */
fun getCommonAnimals(animals1: List<String>, animals2: List<String>): List<String> {
/**
 * Given two lists of animals, return a new list containing the animals that are common to both lists.
 *
 * @param animals1 The first list of animals
 * @param animals2 The second list of animals
 * @return A list containing the animals that are common to both lists
 *
 * Example:
 * animals1 = listOf("elephant", "giraffe", "lion", "rhino")
 * animals2 = listOf("lion", "zebra", "elephant")
 * getCommonAnimals(animals1, animals2) // Output: ["lion", "elephant"]
 */
fun getCommonAnimals(animals1: List<String>, animals2: List<String>): List<String> {

    val commonAnimals = mutableListOf<String>()

    // Iterate over each animal in the first list
    for (animal in animals1) {
        // Check if the animal is in the second list
        if (animal in animals2) {
            // Append the animal to the common animals list
            commonAnimals.add(animal)
        }
    }

    return commonAnimals
}