We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 15e262f commit c2f5934Copy full SHA for c2f5934
src/_DataStructures_/Heaps/MaxHeap/index.js
@@ -14,25 +14,24 @@ class MaxHeap {
14
return this.heap[0] || null;
15
}
16
17
+ // eslint-disable-next-line consistent-return
18
remove() {
19
// return the element at the root
20
const max = this.heap[0] || null;
21
if (this.heap.length > 1) {
22
// move the leaf to the root
23
this.heap[0] = this.heap[this.heap.length - 1];
- this.heap.splice(this.heap.length - 1, 1);
24
+ this.heap.pop();
25
// restore the heapify property
26
// eslint-disable-next-line no-underscore-dangle
27
this.__heapify(0);
28
return max;
29
30
31
if (this.heap.length === 1) {
32
33
34
-
35
- return max;
36
37
38
__heapify(index) {
0 commit comments