Menu
Coddy logo textTech

Recap - Data Pipeline

Part of the Logic & Flow section of Coddy's Ruby journey — lesson 27 of 56.

One challenge that runs a small dataset through a chain of Enumerable methods, the way you'll write Ruby for real.

challenge icon

Challenge

Medium

The array orders is given, each element is a hash with :product, :qty, and :price. Print three lines:

  1. The total revenue across all orders (qty * price, summed). Use map + reduce(:+), or sum { ... }.
  2. The number of orders with qty >= 3 (use count).
  3. The product name of the order with the highest revenue (use max_by).

For the default array, the output is:

59
2
milk

Try it yourself

orders = [
  { product: "apple",  qty: 4, price: 2 },
  { product: "bread",  qty: 1, price: 3 },
  { product: "milk",   qty: 6, price: 4 },
  { product: "cheese", qty: 2, price: 12 }
]

# TODO: total revenue, count of orders with qty >= 3, top-revenue product

All lessons in Logic & Flow