This specific exercise is a codewats Kata, which asks the user to search through an array, and if a String is found, to skip to the next item in the array. The array should then be printed without any of the strings included. [1, 2, "a", "b"] is the array being searching through. I expect [1, 2].
I tried:
def filter_list(l)
print l
i = 0
while i < l.length
l.each do|item| next if item.class == String
return item
i += 1
end
end
I also tried this code without the while loop:
def filter_list(l)
print l
l.each do |item| next if item.class == String
return item
end
print l
end
Both methods return the same result:
1
My code only returns the first element in the array.
Any guidance would be appreciated.