Above average
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Above average
Two loops, one after the other: the first works out the average, the second keeps the numbers above it.
This joins two patterns you have already used, the running total and the filter. Solving a problem in stages like this is how most longer programs are built.
Write above_average(nums) that returns a list of the numbers greater than the average of nums, in their original order. The list is never empty.
Click Run to see the output here.