Array methods (length, include?, flatten)
📖 Scenario: You are organizing a small library's book collection. The books are grouped by genre, and you want to learn how to use Ruby array methods to explore this collection.
🎯 Goal: Build a Ruby program that uses array methods length, include?, and flatten to find out how many genres there are, check if a specific book is in the collection, and combine all books into one list.
📋 What You'll Learn
Create an array of arrays called
library with exact genres and booksCreate a variable called
genre_count to store the number of genresUse
include? method to check if the book 'The Hobbit' is in the libraryUse
flatten method to combine all books into one array called all_booksPrint the results exactly as instructed
💡 Why This Matters
🌍 Real World
Libraries, bookstores, and personal collections often organize items in groups. Knowing how to count groups, check for items, and combine lists helps manage collections easily.
💼 Career
Understanding array methods is essential for data handling in programming jobs, especially when working with lists, databases, or APIs that return nested data.
Progress0 / 4 steps