Closed bjrnt closed 4 years ago
Hello @bjrnt, thanks for your feedback. I will try it within the next
branch to be sure that it is not already fixed. Also I will add your example as a test :)
It should be fixed now.
To allow undefined
as a valid value inside the heap, it checks that the index is not beyond length before any comparison occurs.
I have added tests for custom heaps with custom comparators, and improved the existing ones.
@bjrnt Could you try the next
branch and let me know if it fixed the issue for you?
Thanks :)
Yep, working great now! Thanks for the quick fix! :)
Hi,
Thanks for the library! I've had great use of it in a lot of online coding interviews. :)
Here's a quick reproduction of a bug I found when using custom comparators:
After some digging, I found that inside
getPotentialParent
sometimes callsthis.compare
with anundefined
value. Adding a quicktypeof this.heapArray[j] !== "undefined" &&
to the function solves the issue but I am not sure if this is the best way to handle it. I'd be happy to send a PR with tests if you think this is a good solution to the problem.