| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The empty-input guard was 'if (nums.length < 0) return 0', but length is never negative, so it was dead code. For [] the function then read nums[0] (undefined) and returned Math.max(0, undefined) === NaN instead of 0. Change the guard to 'nums.length === 0' and add a test file.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## master #1905 +/- ##
==========================================
+ Coverage 85.91% 86.06% +0.14%
==========================================
Files 379 379
Lines 19778 19778
Branches 3016 3020 +4
==========================================
+ Hits 16993 17022 +29
+ Misses 2785 2756 -29 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Bug
Dynamic-Programming/MaxNonAdjacentSum.js guards the empty case with:
length is never negative, so this is dead code. For an empty array the function falls through, sets maxIncluding = nums[0] (undefined), skips the loop, and returns Math.max(0, undefined) → NaN instead of 0.
Fix
Use nums.length === 0, matching the clearly-intended behavior. Added a test file (the module had none) covering the empty array, a single element, the documented examples, and an all-negative input.