Skip to content

Commit 0a59548

Browse files
committed
fix regression with empty array in constructor, close #3
1 parent 59739c5 commit 0a59548

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function TinyQueue(data, compare) {
99
this.length = this.data.length;
1010
this.compare = compare || defaultCompare;
1111

12-
if (data) {
12+
if (this.length > 0) {
1313
for (var i = (this.length >> 1); i >= 0; i--) this._down(i);
1414
}
1515
}

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ test('handles edge cases with few elements', function (t) {
5353

5454
t.end();
5555
});
56+
57+
test('handles init with empty array', function (t) {
58+
var queue = tinyQueue([]);
59+
60+
t.same(queue.data, []);
61+
62+
t.end();
63+
});

0 commit comments

Comments
 (0)