gurwinder singh gurwinder singh - 1 month ago 8
Ruby Question

`<=': comparison of Fixnum with Array failed (ArgumentError)

In this code I am trying to remove the last vowel in the word. Once I ran the code, I received an argument error stating "comparison of Fixnum with Array failed(ArgumentError). Please help!

VOWELS = %w( a e i o u)

def hipsterfy(string)

new_string = string.split('')

reversed_string = new_string.reverse

i = 0

while i <= reversed_string

if VOWELS.include?[i]

reversed_string[i] = ('')

i += 1
end
reversed_string
end

reversed_string.reverse

end

Answer

I am sure this is not the only glith with this code, but the error you got came from here:

while i <= reversed_string

it probably should be

while i < reversed_string.length

since reversed_array is an array, and you probably want to compare i against it’s length.