Map/collect for transformation
📖 Scenario: You work at a small bakery. You have a list of prices for different pastries. You want to create a new list that shows the prices with tax added.
🎯 Goal: Build a Ruby program that uses map (also called collect) to add tax to each price in a list.
📋 What You'll Learn
Create an array called
prices with the exact values: 2.5, 3.0, 4.75, 1.25Create a variable called
tax_rate and set it to 0.1 (which means 10% tax)Use
map on prices with block variable price to create a new array prices_with_tax where each price is increased by taxPrint the
prices_with_tax array💡 Why This Matters
🌍 Real World
Adding tax to prices is a common task in stores and online shops to show customers the final cost.
💼 Career
Understanding how to transform lists of data with <code>map</code> is a key skill for Ruby developers working with collections.
Progress0 / 4 steps