Bird
0
0

How can you transform an array of strings to uppercase using iterators in Ruby?

hard📝 Application Q9 of 15
Ruby - Loops and Iteration
How can you transform an array of strings to uppercase using iterators in Ruby?
Aarr.each { |s| s.upcase }
Barr.collect_each { |s| s.upcase }
Carr.for_each { |s| s.upcase }
Darr.map { |s| s.upcase }
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to transform and return new array

    map returns a new array with transformed elements.
  2. Step 2: Check method names and behavior

    each returns original array; for_each and collect_each do not exist.
  3. Final Answer:

    arr.map { |s| s.upcase } -> Option D
  4. Quick Check:

    Transform array with map = B [OK]
Quick Trick: Use map to transform and return a new array [OK]
Common Mistakes:
MISTAKES
  • Using each when map is needed
  • Using non-existent methods
  • Expecting each to return transformed array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes