rspec - Ruby .join method returning length of original array instead of concatenated string -
i tyring repeat word optional number of times. when run programme not seem past input[1].times line
.
code:
def repeat(*input) sentence = [] if input.length == 1 "#{input[0]} #{input[0]}" else input[1].times sentence.push(input[0]) sentence.join(" ") end end end puts repeat("hey!") puts repeat("hey", 3)
output:
hey! hey! 3
you need homecoming sentence, , want bring together sentence outside of times loop.
def repeat(*input) sentence = [] if input.length == 1 "#{input[0]} #{input[0]}" else input[1].times sentence.push(input[0]) end sentence = sentence.join(" ") homecoming sentence end end
ruby rspec tdd
No comments:
Post a Comment