Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed

image text in transcribed

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago

Question

assess the infl uence of national culture on the workplace

Answered: 1 week ago