Bird
0
0

What does the Ruby method reject do when called on an array?

easy📝 Conceptual Q11 of 15
Ruby - Enumerable and Collection Processing
What does the Ruby method reject do when called on an array?
AIt sorts the array in reverse order.
BIt modifies the original array to keep only elements matching the condition.
CIt returns the first element that matches the condition.
DIt returns a new array excluding elements that match the given condition.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of reject

    The reject method filters elements by removing those that satisfy the condition.
  2. Step 2: Compare with other methods

    Unlike select, which keeps matching elements, reject excludes them and returns a new array.
  3. Final Answer:

    It returns a new array excluding elements that match the given condition. -> Option D
  4. Quick Check:

    reject excludes matching elements = A [OK]
Quick Trick: Reject removes items matching condition, returning a new array [OK]
Common Mistakes:
  • Thinking reject modifies the original array
  • Confusing reject with select
  • Assuming reject returns a single element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes