Q:

Write a Ruby program to compute the sum of two arrays (length 3) and return the array which has the largest sum

0

Write a Ruby program to compute the sum of two arrays (length 3) and return the array which has the largest sum.

All Answers

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

def check_array(a, b)
    sum = (a[0]+a[1]+a[2])-(b[0]+b[1]+b[2])
	if(sum >= 0)
		return a
	end
	return b
end
print check_array([1, 3, 5], [2, 4, 4]),"\n"
print check_array([11, 3, 5], [21, 0, -4]),"\n"  

Output:

[2, 4, 4]
[11, 3, 5]

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