/**
 * Given a list of transactions, calculate and return the total income, total expenses,
 * and the resulting balance.
 *
 * @param transactions A list of nested lists representing transactions, where
 * each transaction is of the form [description, amount].
 * @return A triple containing totalIncome (Double), totalExpenses (Double),
 * and balance (Double).
 */
fun calculateTotals(transactions: List<List<Any>>): Triple<Double, Double, Double> {

    var totalIncome = 0.0
    var totalExpenses = 0.0

    for (transaction in transactions) {
        val amount = transaction[1] as Double
        if (amount > 0) {
            totalIncome += amount
        } else {
            totalExpenses += amount
        }
    }

    val balance = totalIncome + totalExpenses
    return Triple(totalIncome, totalExpenses, balance)
}
/**
 * Given a list of transactions, calculate and return the total income, total expenses,
 * and the resulting balance.
 *
 * @param transactions A list of nested lists representing transactions, where
 * each transaction is of the form [description, amount].
 * @return A triple containing totalIncome (Double), totalExpenses (Double),
 * and balance (Double).
 */
fun calculateTotals(transactions: List<List<Any>>): Triple<Double, Double, Double> {
/**
 * Given a list of transactions, calculate and return the total income, total expenses,
 * and the resulting balance.
 *
 * @param transactions A list of nested lists representing transactions, where
 * each transaction is of the form [description, amount].
 * @return A triple containing totalIncome (Double), totalExpenses (Double),
 * and balance (Double).
 */
fun calculateTotals(transactions: List<List<Any>>): Triple<Double, Double, Double> {

    var totalIncome = 0.0
    var totalExpenses = 0.0

    for (transaction in transactions) {
        val amount = transaction[1] as Double
        if (amount > 0) {
            totalIncome += amount
        } else {
            totalExpenses += amount
        }
    }

    val balance = totalIncome + totalExpenses
    return Triple(totalIncome, totalExpenses, balance)
}