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!