Title: [BUG]: MaxProductOfThree not working properly · Issue #1294 · TheAlgorithms/JavaScript · GitHub
Open Graph Title: [BUG]: MaxProductOfThree not working properly · Issue #1294 · TheAlgorithms/JavaScript
X Title: [BUG]: MaxProductOfThree not working properly · Issue #1294 · TheAlgorithms/JavaScript
Description: Description The maxProductOfThree-function in Dynamic-Programming/MaxProductOfThree.js is not working properly when the values of the array vary around 0. I noticed something seemed off when I looked at the code for the function, and dec...
Open Graph Description: Description The maxProductOfThree-function in Dynamic-Programming/MaxProductOfThree.js is not working properly when the values of the array vary around 0. I noticed something seemed off when I look...
X Description: Description The maxProductOfThree-function in Dynamic-Programming/MaxProductOfThree.js is not working properly when the values of the array vary around 0. I noticed something seemed off when I look...
Opengraph URL: https://github.com/TheAlgorithms/JavaScript/issues/1294
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: MaxProductOfThree not working properly","articleBody":"### Description\n\nThe maxProductOfThree-function in Dynamic-Programming/MaxProductOfThree.js is not working properly when the values of the array vary around 0.\r\n\r\nI noticed something seemed off when I looked at the code for the function, and decided to test the function using random arrays of length 4, where the values varied between -3 and 3. The output was compared to the output of a function that calculated all possible products of 3 numbers in the array, and indeed the function produced incorrect outputs.\r\n\r\nExamples arrays that produce incorrect output:\r\n[-2,1,-1,1]: expected = 2, actual = -1.\r\n[-3,0,-1,1]: expected = 3, actual = 0.\r\n[-1,1,-1,1]: expected = 1, actual = -1.\n\n### Expected Behavior\n\nThe expected behavior of the function is to find the largest product that can be produced from 3 numbers of an array. Due to the implementation, it is currently not.\r\n\r\nExpected output of the following arrays of length 4:\r\n[-2,1,-1,1]: expected = 2.\r\n[-3,0,-1,1]: expected = 3.\r\n[-1,1,-1,1]: expected = 1.\n\n### Actual Behavior\n\nActual output of the arrays above:\r\n[-2,1,-1,1]: actual = -1.\r\n[-3,0,-1,1]: actual = 0.\r\n[-1,1,-1,1]: actual = -1.\n\n### Steps to reproduce (if applicable)\n\n1. Call the function maxProductOfThree with the input [-2, 1, -1, 1].\r\n2. Observe that the expected output is clearly 2, since (-2) * (-1) * 1 = 2\r\n3. Observe that the actual output is -1.\n\n### Additional information\n\nI suspect this has to do with the way the max and min variables are initialized to -1 in the function, instead of setting them to null to begin with.","author":{"url":"https://github.com/Xolvez","@type":"Person","name":"Xolvez"},"datePublished":"2023-02-18T15:02:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1294/JavaScript/issues/1294"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5a6cdb28-8a94-73be-bf05-e352b1ed379c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C038:797B1:2A94CD:36A14A:69701CD7 |
| html-safe-nonce | 4550ccb71608427a6b9f5d175aa191df7e0714fb11a2874390c348d001ccabf7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDM4Ojc5N0IxOjJBOTRDRDozNkExNEE6Njk3MDFDRDciLCJ2aXNpdG9yX2lkIjoiNzExNDgyNTg2ODM0NDU2NDk1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc256efccc211435a408dc8b8cdc59a599d206f69f563d65dfe7aed8d55e8469 |
| hovercard-subject-tag | issue:1590370683 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/TheAlgorithms/JavaScript/1294/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7b712230369c06261c9e787cd38b0634bfa8005ed56899984b87a11aac3e87e/TheAlgorithms/JavaScript/issues/1294 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7b712230369c06261c9e787cd38b0634bfa8005ed56899984b87a11aac3e87e/TheAlgorithms/JavaScript/issues/1294 |
| og:image:alt | Description The maxProductOfThree-function in Dynamic-Programming/MaxProductOfThree.js is not working properly when the values of the array vary around 0. I noticed something seemed off when I look... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Xolvez |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043a09521e81f00c45482046b3f38390b8b292cf9a86ad665a632633a072c05c |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 98881eadf8ae73000970c42161c094b0809b1330 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width