Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with my beginner\'s Ruby code. 1 numbers-0 2 5.times do Ixl 3 numbers[x]= g

ID: 3590926 • Letter: H

Question


Help with my beginner's Ruby code.

1 numbers-0 2 5.times do Ixl 3 numbers[x]= gets . chomp . to-f 4 end 5 numbers.index(numbers.max) Instructions from your teacher Write a method/function named max that takes in an array and returns the index of the largest value in the array. Do this manually without the help of any cheating functions. consider an array named numbers: numbers [1,2,0,99,22,3] Then, if we were to give this array to the function/method max: max(numbers) the function would return: since 99 has the largest value in the array ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64- linux]

Explanation / Answer

Answer:- //you can simply use the predefine function to find the max element in array numbers.max_by do |element| element.field end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote