Bird
0
0

Which of the following is the correct syntax to join an array ["a", "b", "c"] into a string separated by dashes in Ruby?

easy📝 Syntax Q12 of 15
Ruby - String Operations
Which of the following is the correct syntax to join an array ["a", "b", "c"] into a string separated by dashes in Ruby?
A["a", "b", "c"].split("-")
B["a", "b", "c"].join("-")
C"a-b-c".join(["a", "b", "c"])
D"a-b-c".split(["a", "b", "c"])
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to combine array elements

    The join method is used on arrays to create a string with a separator.
  2. Step 2: Check the syntax for join with a separator

    The syntax is array.join(separator), so ["a", "b", "c"].join("-") is correct.
  3. Final Answer:

    ["a", "b", "c"].join("-") -> Option B
  4. Quick Check:

    join(array) with separator = correct syntax [OK]
Quick Trick: Use array.join(separator) to combine elements [OK]
Common Mistakes:
  • Using split instead of join to combine
  • Calling join on a string instead of array
  • Passing array as argument to split or join incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes