Skip to content

Commit 1f551a4

Browse files
1011zaozao-maxmourner
authored andcommitted
improved code readability
modified variable name to improve code readability eliminated one variable to make code cleaner
1 parent 38c728f commit 1f551a4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ export default class TinyQueue {
5454
const item = data[pos];
5555

5656
while (pos < halfLength) {
57-
let left = (pos << 1) + 1;
58-
let best = data[left];
59-
const right = left + 1;
57+
let bestChild = (pos << 1) + 1; // initially it is the left child
58+
const right = bestChild + 1;
6059

61-
if (right < this.length && compare(data[right], best) < 0) {
62-
left = right;
63-
best = data[right];
60+
if (right < this.length && compare(data[right], data[bestChild]) < 0) {
61+
bestChild = right;
6462
}
65-
if (compare(best, item) >= 0) break;
63+
if (compare(data[bestChild], item) >= 0) break;
6664

67-
data[pos] = best;
68-
pos = left;
65+
data[pos] = data[bestChild];
66+
pos = bestChild;
6967
}
7068

7169
data[pos] = item;

0 commit comments

Comments
 (0)