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
It would make this library really useful if we could get a list of items less than a certain value or if there were a way to extrapolate that data without mutating the heap.
Here is a function I made which you are welcome to use.
There is an option to provide a compare function in case we need to compare something like {someValue:....} and value without creating a new instance of the objects used in the heap.
The text was updated successfully, but these errors were encountered:
Hi,
It would make this library really useful if we could get a list of items less than a certain value or if there were a way to extrapolate that data without mutating the heap.
Here is a function I made which you are welcome to use.
Heap.prototype.peekTo = function(value,cmp) {
var c;
if(cmp===null) {
cmp=this.cmp;
}
for(c=0;c<this.nodes.length;++c) {
if(cmp(value,this.nodes[c]) <= 0) {
break;
}
}
return this.nodes.slice(0,c);
}
There is an option to provide a compare function in case we need to compare something like {someValue:....} and value without creating a new instance of the objects used in the heap.
The text was updated successfully, but these errors were encountered: