Reject for inverse filtering
📖 Scenario: You work in a store that sells fruits. You have a list of fruits with their prices. You want to find all fruits that are not expensive, meaning their price is less than 5.
🎯 Goal: Build a Ruby program that uses reject to filter out expensive fruits from the list, keeping only the affordable ones.
📋 What You'll Learn
Create a hash called
fruits with these exact entries: 'apple' => 3, 'banana' => 2, 'cherry' => 7, 'date' => 6, 'elderberry' => 1Create a variable called
price_limit and set it to 5Use
reject on fruits with a block that removes fruits with price greater than or equal to price_limitPrint the resulting hash of affordable fruits
💡 Why This Matters
🌍 Real World
Filtering items based on conditions is common in shopping apps, inventory management, and data analysis.
💼 Career
Knowing how to filter collections efficiently is important for software developers working with data and user interfaces.
Progress0 / 4 steps