JS solution.
On the line 13 absolute values of target_diff and smallest_difference are compared. And if if-clause returns true, smallest_difference will be overwritten:
if (Math.abs(target_diff) < Math.abs(smallest_difference)) {
smallest_difference = target_diff; // save the closest difference
}
On the line 17 there is the same comparison:
if (Math.abs(target_diff) < Math.abs(smallest_difference) ||
Why is it needed since it always returns false? (At least for the problem’s test cases)