Bird
0
0

Which of the following expressions returns elements from index 0 up to but not including index 3 in arr = [7, 8, 9, 10, 11]?

easy📝 Conceptual Q2 of 15
Ruby - Arrays
Which of the following expressions returns elements from index 0 up to but not including index 3 in arr = [7, 8, 9, 10, 11]?
Aarr[0..3]
Barr[0...3]
Carr[1..3]
Darr[1...3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the difference between .. and ...

    The .. operator includes the end index, while ... excludes it.
  2. Step 2: Select the correct range for indices 0 up to but not including 3

    Using 0...3 excludes index 3, so it selects indices 0, 1, and 2.
  3. Final Answer:

    arr[0...3] -> Option B
  4. Quick Check:

    Three-dot range excludes end index = arr[0...3] [OK]
Quick Trick: Use ... to exclude the end index in ranges [OK]
Common Mistakes:
MISTAKES
  • Using .. which includes the end index
  • Starting range from 1 instead of 0
  • Confusing inclusive and exclusive ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes