/**
 * Given a list of persons, calculate the average age using list comprehension and a for loop.
 *
 * @param persons a list of maps containing person information such as 'name', 'age', 'gender', etc.
 * @return the average age of all persons in the list
 */
fun calculateAverageAge(persons: List<Map<String, Any>>): Double {

    // Extract ages using list comprehension
    val ages = persons.map { it["age"] as Int }

    // Calculate the average age using a for loop
    var totalAge = 0
    for (age in ages) {
        totalAge += age
    }
    val averageAge = totalAge.toDouble() / persons.size

    return averageAge
}
/**
 * Given a list of persons, calculate the average age using list comprehension and a for loop.
 *
 * @param persons a list of maps containing person information such as 'name', 'age', 'gender', etc.
 * @return the average age of all persons in the list
 */
fun calculateAverageAge(persons: List<Map<String, Any>>): Double {
/**
 * Given a list of persons, calculate the average age using list comprehension and a for loop.
 *
 * @param persons a list of maps containing person information such as 'name', 'age', 'gender', etc.
 * @return the average age of all persons in the list
 */
fun calculateAverageAge(persons: List<Map<String, Any>>): Double {

    // Extract ages using list comprehension
    val ages = persons.map { it["age"] as Int }

    // Calculate the average age using a for loop
    var totalAge = 0
    for (age in ages) {
        totalAge += age
    }
    val averageAge = totalAge.toDouble() / persons.size

    return averageAge
}