You will be building out Ruby's #join
method. It shouldn't change the array it's called on.
animals = ["aardvark", "hedgehog", "wallaby"]
animals.my_join(", ")
#=> "aardvark, hedgehog, wallaby"
animals
#=> ["aardvark", "hedgehog", "wallaby"]
It defaults to just putting every element into a string with no string inbetween if not passed an argument.
animals.my_join
#=> "aardvarkhedgehogwallaby"
If the elements in the array are not strings, it converts them to strings.
symbols = [:hi, :there]
symbols.my_join(" ")
#=> "hi there"
numbers = [ 1, 3, 5, 7 ]
numbers.my_join(" + ")
#=> "1 + 3 + 5 + 7"
You may not call on Ruby's #join
method to accomplish this task.
View My Join on Learn.co and start learning to code for free.