Bird
0
0

How can you check if the number 10 exists in a flattened version of this array?

hard📝 Application Q9 of 15
Ruby - Arrays
How can you check if the number 10 exists in a flattened version of this array?
arr = [5, [10, 15], [20, [25]]]
Aarr.flatten.include?(10)
Barr.include?(10)
Carr.length.include?(10)
Darr.flatten.length(10)
Step-by-Step Solution
Solution:
  1. Step 1: Flatten the nested array

    Use arr.flatten to get a single-level array.
  2. Step 2: Check if 10 is included

    Use include?(10) on the flattened array to check presence.
  3. Final Answer:

    arr.flatten.include?(10) -> Option A
  4. Quick Check:

    Flatten then include? to check nested elements [OK]
Quick Trick: Flatten first, then use include? to check elements [OK]
Common Mistakes:
  • Checking include? on original nested array
  • Using length.include? which is invalid
  • Calling length with argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes