Simple question I suspect, but nonetheless:
I'm looking for an efficient way to grab the first element from an array that does not have a particular value. So for example, given
["Fred", "Fred", "Fred", "James", "Alex", "Fred"]
I'd like to return "James"
I can do this via something like
thearray.select { |i| i != "Fred" }.first
but that's going to iterate over every element (including alex and the last fred) before returning the value.
So - I'm hoping for a simple way to do this that won't iterate through the entire array - just until it finds a value. Any ideas apprecated.