MCPcopy Index your code
hub / github.com/datastructures-js/priority-queue / remove

Method remove

src/priorityQueue.js:87–105  ·  view source on GitHub ↗

* Removes all elements that match a criteria in the callback * @public * @param {function} cb * @returns {array}

(cb)

Source from the content-addressed store, hash-verified

85 * @returns {array}
86 */
87 remove(cb) {
88 if (typeof cb !== 'function') {
89 throw new Error('PriorityQueue remove expects a callback');
90 }
91
92 const removed = [];
93 const dequeued = [];
94 while (!this.isEmpty()) {
95 const popped = this.pop();
96 if (cb(popped)) {
97 removed.push(popped);
98 } else {
99 dequeued.push(popped);
100 }
101 }
102
103 dequeued.forEach((val) => this.push(val));
104 return removed;
105 }
106
107 /**
108 * Checks if the queue contains an element that matches a criteria

Callers

nothing calls this directly

Calls 4

isEmptyMethod · 0.95
popMethod · 0.95
pushMethod · 0.95
pushMethod · 0.65

Tested by

no test coverage detected