-
Notifications
You must be signed in to change notification settings - Fork 934
Update heap.js #114
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
Update heap.js #114
Conversation
Fix proper parent index fetching
Hi @Balaji1202! Thanks a lot for the fix. Could you please add a unit test that captures this bug fix?
Hey @amejiarosario!
The issue seems to be a little complicated and the ceil operation is little weird from javascript side too.
The operation Math.ceil(i / 2 - 1)
is a lot similar to Math.ceil(i / 2) - 1
both in terms of BODMAS rule and javascript execution of Math.ceil method.
But, for an input of 1, the javascript engine equates Math.ceil(-0.5) to negative zero -0
(validity of negative zero is debatable). But, since 0 equals -0, your validation seems to pass for all inputs.
So, I feel my fix may not add any value since there is not any issue in first place. But, if you are worried about reading confusion for your readers with the priority of the execution in the statement, think about merging it. Else feel free to close the PR.
:>)
Thanks!
Ah, I see now where you are coming from. I agree this change makes it easier to reason about. Also, it avoids the weird -0
case. Thanks for taking the time to explain and creating the PR
Fix proper parent index fetching