Question: I new to working in ruby and am having some triuble with 2 questions i have. The First one is i need to find the

I new to working in ruby and am having some triuble with 2 questions i have.

The First one is i need to find the 2 largest elements of an array and sum them, also for an empty array it should return zero and for an array with one element return the single element, this is what i have so far.

def max_2_sum arr # YOUR CODE HERE sorted=arr.sort sorted[-1]+sorted[-2] end

the second part add code that should retuen true if any two elements in the array of integers (arr) sum to the integer n. sum_to_n?([],n) should return false for any value of n, by definition. any single element array should return false

thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!