Bird
0
0

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

easy📝 Conceptual Q11 of 15
Ruby - Arrays
What does the Ruby method sort do when called on an array?
AIt arranges the elements in ascending order.
BIt reverses the order of elements.
CIt removes duplicate elements.
DIt shuffles the elements randomly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of sort

    The sort method arranges elements in ascending order by default.
  2. Step 2: Compare with other methods

    Unlike reverse which flips order, sort orders elements from smallest to largest.
  3. Final Answer:

    It arranges the elements in ascending order. -> Option A
  4. Quick Check:

    sort = ascending order [OK]
Quick Trick: Remember: sort arranges ascending, reverse flips order [OK]
Common Mistakes:
  • Confusing sort with reverse
  • Thinking sort removes duplicates
  • Assuming sort shuffles elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes