Title: fix: handle empty array in maximumNonAdjacentSum by shaked-shlomo · Pull Request #1905 · TheAlgorithms/JavaScript · GitHub
Open Graph Title: fix: handle empty array in maximumNonAdjacentSum by shaked-shlomo · Pull Request #1905 · TheAlgorithms/JavaScript
X Title: fix: handle empty array in maximumNonAdjacentSum by shaked-shlomo · Pull Request #1905 · TheAlgorithms/JavaScript
Description: Bug Dynamic-Programming/MaxNonAdjacentSum.js guards the empty case with: if (nums.length < 0) return 0 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. maximumNonAdjacentSum([]) // NaN (should be 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.
Open Graph Description: Bug Dynamic-Programming/MaxNonAdjacentSum.js guards the empty case with: if (nums.length < 0) return 0 length is never negative, so this is dead code. For an empty array the function falls throu...
X Description: Bug Dynamic-Programming/MaxNonAdjacentSum.js guards the empty case with: if (nums.length < 0) return 0 length is never negative, so this is dead code. For an empty array the function falls t...
Opengraph URL: https://github.com/TheAlgorithms/JavaScript/pull/1905
X: @github
Domain: Github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bd7f31c3-88ff-5742-0b32-ad1c89eb8802 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9294:162460:23B3F3C:3148328:6A63167E |
| html-safe-nonce | 247191111b586b97815b2a663ead76440f2ac1afb05df2ac126c8104509f8bae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mjk0OjE2MjQ2MDoyM0IzRjNDOjMxNDgzMjg6NkE2MzE2N0UiLCJ2aXNpdG9yX2lkIjoiNjkyNDkxNzExNjIwNDQyMjc4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9a272de22c3e393580f7f9ef70acaedd151470e06d4d91e42e46f65e8bec47be |
| hovercard-subject-tag | pull_request:3784463152 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/TheAlgorithms/JavaScript/pull/1905/files |
| twitter:image | https://avatars.githubusercontent.com/u/167336994?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/167336994?s=400&v=4 |
| og:image:alt | Bug Dynamic-Programming/MaxNonAdjacentSum.js guards the empty case with: if (nums.length < 0) return 0 length is never negative, so this is dead code. For an empty array the function falls throu... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1a6c056e02f174fffc096c521ec0ff6fb83e40a2ec8cb8875466ec1524872dd6 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/TheAlgorithms/JavaScript git https://github.com/TheAlgorithms/JavaScript.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 97086543 |
| octolytics-dimension-repository_nwo | TheAlgorithms/JavaScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97086543 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/JavaScript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6a93e25585f487ddff9e3996c06d5b869d6e1828 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width