One call inside another
One cloth bag holds the morning fares. Another holds the evening fares. One line finds which bag has the bigger total.
max(total(morning), total(evening)) Step 1 of 4
max(total(morning), total(evening))total(morning)finishes first: 30.total(evening)finishes next: 34.maxpicks the larger: 34.
Press the button below. Watch each call turn into a number.
Loading lab…
The rule
The list morning holds 8, 6, 10 and 6 rupees. The list evening holds 12, 8, 6 and 8.
total adds up a bag and hands back the sum. max takes two numbers and hands back the larger.
A call is a value. So a call can sit inside another line. The inside call runs first. It hands its value up. Only then does the outer line have what it needs.
`` max(total(morning), total(evening)) ``
total(morning)runs all the way through. It gives 8 + 6 + 10 + 6 = 30.total(evening)runs. It gives 12 + 8 + 6 + 8 = 34.max(30, 34)runs. It gives 34.
So the evening bag has the bigger total, 34.