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

Method contains

src/priorityQueue.js:113–131  ·  view source on GitHub ↗

* Checks if the queue contains an element that matches a criteria * @public * @param {function} cb * @returns {boolean}

(cb)

Source from the content-addressed store, hash-verified

111 * @returns {boolean}
112 */
113 contains(cb) {
114 if (typeof cb !== 'function') {
115 throw new Error('PriorityQueue contains expects a callback');
116 }
117
118 let found = false;
119 const dequeued = [];
120 while (!this.isEmpty()) {
121 const popped = this.pop();
122 dequeued.push(popped);
123 if (cb(popped)) {
124 found = true;
125 break;
126 }
127 }
128
129 dequeued.forEach((val) => this.push(val));
130 return found;
131 }
132
133 /**
134 * Returns the number of elements in the queue

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