gurwinder singh gurwinder singh - 1 year ago 121
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



Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download