Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started