Design an Ordered Stream LeetCode solution in JavaScript

1
var OrderedStream = function (n) {
2
this.pointer = 0;
3
this.streamArray = new Array(n).fill(undefined);
4
};
5
OrderedStream.prototype.insert = function (idKey, value) {
6
this.streamArray[idKey - 1] = value;
7
if (this.streamArray[this.pointer] === undefined) {
8
return [];
9
} else {
10
const result = [];
11
while (this.streamArray[this.pointer] !== undefined) {
12
result.push(this.streamArray[this.pointer]);
13
this.pointer++;
14
}
15
return result;
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0