Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions