Compact for removing nil values
📖 Scenario: You have a list of items where some are missing (nil). You want to clean this list by removing all the missing items.
🎯 Goal: Build a Ruby program that uses compact to remove all nil values from an array.
📋 What You'll Learn
Create an array called
items with some nil valuesCreate a variable called
clean_items that uses compact on itemsPrint the
clean_items array💡 Why This Matters
🌍 Real World
Cleaning data lists by removing missing or empty values is common in many programs, like filtering user inputs or processing data files.
💼 Career
Knowing how to clean arrays efficiently helps in data processing, web development, and scripting tasks where data quality matters.
Progress0 / 4 steps