Write a Ruby program to compute the sum of two arrays (length 3) and return the array which has the largest sum.
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]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer