map / select / reduce

Kiosk totals.

Kiosk totals with Enumerable.

Goal

Sum shillings for busy kiosks.

units = [12, 8, 5]
puts units.map { |n| n * 40 }.inspect
rows = [
  { city: "Nairobi", units: 12 },
  { city: "Mombasa", units: 8 },
  { city: "Kisumu", units: 5 },
]
puts rows.select { |r| r[:units] >= 8 }.map { |r| r[:city] }.inspect
units = [12, 8, 5]
puts units.reduce(0) { |acc, n| acc + n }
rows = [
  { city: "Nairobi", shillings: 480 },
  { city: "Nakuru", shillings: 160 },
]
puts rows.reduce(0) { |acc, r| acc + r[:shillings] }