Bird
0
0

What will this Ruby code output?

medium📝 Predict Output Q5 of 15
Ruby - String Operations
What will this Ruby code output?
sentence = "a,b,c,d"
array = sentence.split(',')
puts array.join('')
Aa b c d
Babcd
Ca,b,c,d
Da-b-c-d
Step-by-Step Solution
Solution:
  1. Step 1: Split string by comma

    sentence.split(',') creates ["a", "b", "c", "d"].
  2. Step 2: Join array with empty string

    Joining with '' concatenates elements without spaces or separators, resulting in "abcd".
  3. Final Answer:

    abcd -> Option B
  4. Quick Check:

    split by ',' then join with '' = abcd [OK]
Quick Trick: Join with empty string removes separators [OK]
Common Mistakes:
  • Expecting spaces between letters
  • Using wrong join separator
  • Confusing split and join order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes