Back to course home
0% completed
Vote For New Content
There is some redundancy in the solution.Referring to JS:` if (target_diff === 0...
seth
Jan 8, 2022
There is some redundancy in the solution. Referring to JS:
if (target_diff === 0) { // we've found a triplet with an exact sum return targetSum - target_diff; // return sum of all the numbers }
can just be
if (target_diff === 0) { return targetSum; }
This one is in all solutions.
And the following is only in the JS:
if (Math.abs(target_diff) < Math.abs(smallest_difference)) { smallest_difference = target_diff; // save the closest difference }
is redundant, because it's also in the next if conditional with the exact same result.
0
0
Comments
Comments
Design Gurus4 years ago
Thanks for pointing these out!
On this page
Problem Statement
Try it yourself