0% completed
Can you please help me in explaining the if condition '(Math.abs(targetDiff) == ...
Abhinav Gupta
Jan 28, 2022
Can you please help me in explaining the if condition '(Math.abs(targetDiff) == Math.abs(smallestDifference) && targetDiff > smallestDifference)'
Also, can you please help me with an example?
Thanks
0
0
Comments
Abhinav Gupta4 years ago
Without above if condition also, examples mentioned in this unit are giving correct output.
Nirbhay Lourembam2 years ago
I think the above is for checking negative values. But I also do not understand what this checks exactly.
(Math.abs(targetDiff) == Math.abs(smallestDifference)
I think this means that if the targetDiff or smallestDifference is negative then we compare the absolu...
Ming Chen2 years ago
This if condition is checking that if targetDiff and smallestDifference absolute values are equal, then, they would check to see if targetDiff is a larger number than smallestDifference because it would be the value with the smaller sum. (It's confusing because the nami...
On this page
Problem Statement
Try it yourself