Bird
0
0

Find the bug in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - String Operations
Find the bug in this Ruby code snippet:
data = "1|2|3|4"
array = data.split('|')
result = array.join(', ')
puts result
Ajoin separator should be '|'
BNo bug, code works as intended
Csplit delimiter should be ','
Dsplit should be called without argument
Step-by-Step Solution
Solution:
  1. Step 1: Analyze split delimiter

    Data string uses '|' as separator, so splitting by '|' is correct.
  2. Step 2: Analyze join separator

    Joining with ', ' creates a comma-separated string, which is valid and intentional.
  3. Final Answer:

    No bug, code works as intended -> Option B
  4. Quick Check:

    split and join separators match intended output [OK]
Quick Trick: Check delimiters match data format [OK]
Common Mistakes:
MISTAKES
  • Changing correct delimiters unnecessarily
  • Confusing split and join separators
  • Assuming split needs no argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes