Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Enumerable and Collection Processing
What is the output of this Ruby code?
nums = [10, 15, 20, 25]
result = nums.select { |n| n > 15 }
puts result.inspect
A[10, 15]
B[20, 25]
C[15, 20, 25]
D[]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the condition inside select

    The block filters numbers greater than 15.
  2. Step 2: Identify which elements satisfy the condition

    Only 20 and 25 are greater than 15, so they are selected.
  3. Final Answer:

    [20, 25] -> Option B
  4. Quick Check:

    Filter condition > 15 = [20, 25] [OK]
Quick Trick: Select returns elements matching the block condition [OK]
Common Mistakes:
  • Including elements equal to 15
  • Confusing greater than with greater or equal
  • Expecting original array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes