Q:

Write a Ruby program to find the larger between the first and last elements of a given array of integers of length 3

0

 Write a Ruby program to find the larger between the first and last elements of a given array of integers of length 3. Replace all the other values to be that value. Return the changed array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
    maxVal = []
   	maxVal[0] = nums[0]
	if(nums[2] >= maxVal[0])
		maxVal[0] = nums[2]
	maxVal[1] = maxVal[0]
	maxVal[2] = maxVal[0]
	end
	return maxVal
end
print check_array([1, 2, 5]),"\n" 
print check_array([1, 2, 3]),"\n" 
print check_array([1, 2, 4]) 
 Output:
[5, 5, 5]
[3, 3, 3]
[4, 4, 4]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now