Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2f5934

Browse files
committed
fix: used pop() instead of splice()
1 parent 15e262f commit c2f5934

File tree

1 file changed

+3
-4
lines changed
  • src/_DataStructures_/Heaps/MaxHeap

1 file changed

+3
-4
lines changed

‎src/_DataStructures_/Heaps/MaxHeap/index.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ class MaxHeap {
1414
return this.heap[0] || null;
1515
}
1616

17+
// eslint-disable-next-line consistent-return
1718
remove() {
1819
// return the element at the root
1920
const max = this.heap[0] || null;
2021
if (this.heap.length > 1) {
2122
// move the leaf to the root
2223
this.heap[0] = this.heap[this.heap.length - 1];
23-
this.heap.splice(this.heap.length-1,1);
24+
this.heap.pop();
2425
// restore the heapify property
2526
// eslint-disable-next-line no-underscore-dangle
2627
this.__heapify(0);
2728
return max;
2829
}
2930

3031
if (this.heap.length === 1) {
31-
this.heap.splice(this.heap.length-1,1);
32+
this.heap.pop();
3233
return max;
3334
}
34-
35-
return max;
3635
}
3736

3837
__heapify(index) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /