Question: RUBY: For the following code, 1)I need a code that returns the sum of the elements of the arr array 2)I need a code that

RUBY: For the following code,

 RUBY: For the following code, 1)I need a code that returns

the sum of the elements of the arr array 2)I need a

1)I need a code that returns the sum of the elements of the arr array

2)I need a code that return the sum of the two largest elements of the array

-For an empty array it should return zero

-For an array with just one element, it should return that element

3)Lastly I need the code that will return 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

Will put code here

code that return the sum of the two largest elements of the

3 RSpec.configure do |configl 5 end 7 describe 'Ruby Basics 1 Part I' do 4 config.filter_run_excluding :disabled => true describe"#sum" do 9 10 it "should be defined" do expect sum ([1,3,4]) .not_to raise_error 12 13 14 15 end it "returns correct sum [20 points]" , points: 20 do expect(sum ([1,2,3,4,5])).to be_a_kind_of Fixnum expect(sum(1,2,3,4,5])).to eq(15) expect (sum (1,2,3,4,-5])).to eq(5) expect (sum ([1,2,3,4,-5,5,-100])).to eq (-90) 17 end 20 21 it "works on the empty array [10 points]", points: 10 do expect { sum() }.not to raise error expect (sum([])).to be_zero 23 24 end end 26 end 27 28 describe Ruby Basics 1 Part II' do 29 30 31 describe "#max-2-sum" do it "should be defined" do expect max_2_sum (1,2,3]) .not to raise_error end it "returns the correct sum [7 points]", points: 7 do expect (max_2_sum(1,2,3,4,5])).to be_a_kind_of Fixnum expect (max_2_sum([1,-2,-3,-4,-5])).to eq(-1) 34 36 37 end it 'works even if 2 largest values are the same [3 points]', points: 3 do

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!