Challenge 2: reduce for a Shopping Total — Solution cart = [ { item: "Book", price: 12.99 }, { item: "Pen", price: 1.50 }, { item: "Notebook", price: 4.25 } ] # Explicit block total = cart.reduce(0) { |sum, entry| sum + entry[:price] } puts total # Shorthand: map out the prices first, then reduce(:+) total_shorthand = cart.map { |entry| entry[:price] }.reduce(:+) puts total_shorthand =begin Output: 18.74 18.74 Notes: - The explicit-block version starts the accumulator (sum) at 0 and adds each entry's :price on every step of the reduce. - The shorthand version first uses .map to pull out just the price from each hash into a plain array ([12.99, 1.50, 4.25]), then calls reduce(:+) with no block at all — the symbol :+ tells reduce which operator to fold the array with. - reduce(:+) only works cleanly here because .map already reduced the data down to a flat array of numbers; reduce(:+) can't reach inside a hash on its own the way the explicit block version can. =end