Select/filter for filtering
📖 Scenario: You are managing a small bookstore's inventory. You want to find all books that are priced below a certain amount to offer a discount.
🎯 Goal: Build a Ruby program that filters a list of books to find only those priced below a set threshold using the select method.
📋 What You'll Learn
Create a hash called
books with these exact entries: 'Ruby Basics' => 25, 'JavaScript Guide' => 40, 'Python 101' => 30, 'HTML & CSS' => 20Create a variable called
max_price and set it to 30Use
select on books to create a new hash called affordable_books containing only books with price less than max_pricePrint
affordable_books to display the filtered books💡 Why This Matters
🌍 Real World
Filtering items by price is common in online stores to show discounts or deals.
💼 Career
Understanding how to filter collections is important for data processing and building user-friendly applications.
Progress0 / 4 steps