- 
 
 - 
  Notifications
 
You must be signed in to change notification settings  - Fork 30.9k
 
Properly detect min and max element in array #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello
I noticed that the smallestElement which was found with reduce function is equal to 0 which is not correct, because the notSortedArr does not contains 0.
The smallest element in this array is 1.
The bug is caused because of the initial value given to the reduced function.
I rewrote the 2 declarations using Math.min and Math.max which are more concise and fewer locs.
Best of luck!
Yavorski
Codecov Report
Merging #224 into master will not change coverage.
The diff coverage isn/a.
@@ Coverage Diff @@ ## master #224 +/- ## ===================================== Coverage 100% 100% ===================================== Files 143 143 Lines 2554 2554 Branches 422 422 ===================================== Hits 2554 2554
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 5d12638...aef8f8a. Read the comment docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This set smallestElement to 0, which is not correct.
The smallest element in this array is 1.
 
 
 
 MaksymMalin
 
 
 
 commented
 Oct 13, 2018 
 
 
 
 
 
 
 lazarljubenovic
 
 
 
 commented
 Oct 13, 2018 
 
 
 
0 is wrong there indeed but why would you put 1 instead?
The correct starting values for the reduce way of calculating extrema are Infinity for the minimum and -Infinity for the maximum.
@lazarljubenovic not putting 1 at all, this is just the answer in this particular case with this specific array in mind. See diff for more details.
@yavorski , good catch. Thank you for PR.
No description provided.