Recall & Review
beginner
What does the
length method do when called on an array in Ruby?It returns the number of elements in the array. Think of it like counting how many items are in a basket.
Click to reveal answer
beginner
How does the
include? method work on an array?It checks if a specific item is inside the array and returns
true if found, otherwise false. Like asking, "Is this toy in my box?"Click to reveal answer
intermediate
What is the purpose of the
flatten method on an array?It takes an array that has other arrays inside it and turns it into one simple list without nested arrays. Like spreading out a stack of papers into one flat pile.
Click to reveal answer
beginner
What will
[1, 2, 3].include?(2) return?It will return
true because the number 2 is inside the array.Click to reveal answer
intermediate
What is the result of
[1, [2, 3], 4].flatten?The result is
[1, 2, 3, 4]. The nested array [2, 3] is flattened into the main array.Click to reveal answer
What does
array.length return?✗ Incorrect
length counts how many items are in the array.
What will
["apple", "banana"].include?("banana") return?✗ Incorrect
include? returns true if the item is found in the array.
What does
flatten do to an array?✗ Incorrect
flatten removes nested arrays by combining all elements into one list.
What is the output of
[1, 2, 3].length?✗ Incorrect
The array has 3 elements, so length returns 3.
What will
[1, [2, [3, 4]]].flatten return?✗ Incorrect
flatten flattens all levels of nesting by default, resulting in [1, 2, 3, 4].
Explain how you would check if an array contains a specific item in Ruby.
Think about asking if your list has a certain thing inside.
You got /3 concepts.
Describe what happens when you use the flatten method on an array with nested arrays.
Imagine spreading out a stack of papers into one flat pile.
You got /3 concepts.