File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed
src/_DataStructures_/Heaps/MaxHeap Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -14,25 +14,24 @@ class MaxHeap {
14
14
return this . heap [ 0 ] || null ;
15
15
}
16
16
17
+ // eslint-disable-next-line consistent-return
17
18
remove ( ) {
18
19
// return the element at the root
19
20
const max = this . heap [ 0 ] || null ;
20
21
if ( this . heap . length > 1 ) {
21
22
// move the leaf to the root
22
23
this . heap [ 0 ] = this . heap [ this . heap . length - 1 ] ;
23
- this . heap . splice ( this . heap . length - 1 , 1 ) ;
24
+ this . heap . pop ( ) ;
24
25
// restore the heapify property
25
26
// eslint-disable-next-line no-underscore-dangle
26
27
this . __heapify ( 0 ) ;
27
28
return max ;
28
29
}
29
30
30
31
if ( this . heap . length === 1 ) {
31
- this . heap . splice ( this . heap . length - 1 , 1 ) ;
32
+ this . heap . pop ( ) ;
32
33
return max ;
33
34
}
34
-
35
- return max ;
36
35
}
37
36
38
37
__heapify ( index ) {
You can’t perform that action at this time.
0 commit comments