I want to find the difference between two numbers (positive integers) without returning any positive or negative sign.
Just like
Diff(2,5) => 3
Diff(5,2) => 3.
And Not
(2 - 5) => -3
You should simply return absolute value:
def diff(a, b)
(a - b).abs
end
diff(2, 5)
# => 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With