Question: I'm doing a method that return element that appears earlier in array // def first_in_array(arr, el1, el2) if arr.index(el1) < arr.index(el2) return el1 else return
I'm doing a method that return element that appears earlier in array
// def first_in_array(arr, el1, el2) if arr.index(el1) < arr.index(el2) return el1 else return el2 end
end
puts first_in_array(["a", "b", "c", "d"], "d", "b"); # => "b" puts first_in_array(["cat", "bird" ,"dog", "mouse" ], "dog", "mouse"); # => "dog"
//
Why el1 => b ?
isnt it supposed that el1 = d and el2 = b ?
since el1 is index 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
