I'm getting the following error when I run my code from my rspec file:
pad pads element to the end of an array
Failure/Error: expect(pad(array,array.length + pad_size, 'apple')).to eq(array+Array.new(pad_size, 'apple'))
expected: ["apple", "apple", "apple",...]
my current code is:
def pad!(array, min_size, value = nil) #destructive
difference = min_size-array.length
difference.times {array << value}
array
end
def pad(array, min_size, value = nil) #non-destructive
difference = min_size-array.length
difference.times {array << value}
array.clone
end
Can anyone help me figure out why it's giving me this error message? I thought that {array << value } was adding new elements to the end of my array inputs. Thank you!
new_array = array.cloneshould go up.