Here's my code:
array = ["b", "c", "a", "e", "d", "g", "i", "f"]
array.each_index do |letter|
if array[letter] == ("a" || "e" || "i" || "o" || "u")
puts "found #{array[letter]}"
end
end
found a
found e
found i
found a
if array[letter] == ("e" || "a" || "i" || "o" || "u")
found e
found a
array
x || y
is x
if x
is truthy, y
otherwise. "a"
is truthy (everything except nil
and false
is truthy, those two and only those two are falsey), therefore "a" || whatever_it_doesnt_matter
is always "a"
.
So,
if array[letter] == ("a" || "e" || "i" || "o" || "u")
is equivalent to
if array[letter] == ("a" || ("e" || ("i" || ("o" || "u"))))
which evaluates to
if array[letter] == ("a" || ("i" || ("o" || "u")))
which evaluates to
if array[letter] == ("a" || ("o" || "u"))
which evaluates to
if array[letter] == ("a" || "u")
which evaluates to
if array[letter] == "a"