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