The error in your code is that you're using the .find
method incorrectly. The syntax you're using is from Ruby's Enumerable module, but you're trying to call it on an array directly.
To fix this, you can use the .index
method instead to find the index of the element that matches the given condition. Here's the corrected code:
main.rb38 chars2 lines
This will output 2
because the element 6
(at index 2) is the first element that satisfies the condition e < 9
.
Alternatively, if you want to find the element itself instead of its index, you can use the .find
method as follows:
main.rb37 chars2 lines
This will output 6
, the first element that satisfies the condition.
Remember to use puts
to print the result to the console.
gistlibby LogSnag