-
Code def verify_sum(a,b) return false if a.nil? || b.nil? a.sum == b.sum end
Test Cases # From Ruby 3.0, RSpec is used under the hood. # See https://rspec.info/ # Defaults to the global `describe` for backwards compatibility, but `RSpec.desribe` works as well. describe "Example" do it "should return the sum" do expect(verify_sum("Sebastian", "Patricia")).to eq(false) expect(verify_sum("Anna", "Nana")).to eq(true) expect(verify_sum("John", nil)).to eq(false) # The following is still supported, but new tests should now use them. # Test.assert_equals(add(1, 1), 2) end end
Output:
-
Code def verify_sum(a,b)a.sum==b.sum rescue !1enddef verify_sum(a,b)a&&b&&a.sum==b.sum||!1end- def verify_sum(a,b)
- return false if a.nil? || b.nil?
- a.sum == b.sum
- end
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}