You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var Heap = require('heap');
var cmp = function (A, B) { return B - A; };
var L = [3, 1, 2];
Heap.heapify(L, cmp);
while (L.length) {
console.log(Heap.pop(L));
}
Produces:
3
1
2
Instead of (3, 2, 1)
The text was updated successfully, but these errors were encountered:
Looking through the code, the static method Heap.heapify returns an array sorted using your comparer (while also munging the array you pass it as mentioned in #18 ). If you want to use it similar to your test case you can do
var Heap = require('heap');
var cmp = function (A, B) { return B - A; };
var L = [3, 1, 2];
var L2 = Heap.heapify(L, cmp);
while (L2.length) {
console.log(L2.pop());
}
Test case below.
Produces:
Instead of (3, 2, 1)
The text was updated successfully, but these errors were encountered: