# Rspec for Data Structures Exercises

I don’t quite get the logic behind two rspec exercises for Data Structures Exercises:

`# Write a method that returns the range of its argument (an array of integers).`

``````describe "range" do
it "gets the range of an array of numbers" do
expect(range([-1, 5, 0])).to eq(6)
end

it "correctly returns a range of 0" do
expect(range([0, 0])).to eq(0)
end
end
``````

And

``````# Write a method that returns the range of a string of comma-separated integers,
# e.g., str_range("4,1,8") #=> 7

describe "str_range" do
it "returns the correct range for numbers out of order" do
expect(str_range("4,1,8")).to eq(7)
end

it "returns 0 when the range is 0" do
expect(str_range("0,0")).to eq(0)
end
end
``````

Specifically, why there is 4 in string “4,1,8” in order to return 7? I don’t really see any connections between first and second rspec.

Any hint would be appreciated.

Thanks!

When they mean range, they are talking about the difference between the largest and smallest number in the array.
So for the first rspec, 5 (largest number) - -1 (smallest number) == 6
For the second rspec, 8 (largest number) - 1 (smallest number) == 7.

The first rspec is testing your ability to pinpoint the largest and smallest value given an array and calculate the difference, while the second is looking for you to do the same as what you did for the first rspec, but you first need to put the string into proper integer format so you can calculate the difference (essentially, convert the string into a similar array as the first rspec so you do the same exact thing).

Hope that helps!

Ok, now I get it.

Thanks!