{"ScriptPreparationCode":"function QueueItem(value) {\r\n this.value = value;\r\n this.next = void 0;\r\n}\r\n\r\nfunction Queue() {\r\n this.first = void 0;\r\n this.last = void 0;\r\n}\r\nQueue.prototype.enqueue = function (value) {\r\n var wasEmpty = !this.first;\r\n var item = new QueueItem(value);\r\n if (wasEmpty) {\r\n this.first = item;\r\n } else {\r\n this.last.next = item;\r\n }\r\n this.last = item;\r\n return wasEmpty;\r\n};\r\nQueue.prototype.dequeue = function () {\r\n var first = this.first;\r\n if (first) {\r\n this.first = first.next;\r\n }\r\n if (first === this.last) {\r\n this.last = void 0;\r\n }\r\n return first.value; \r\n};\r\nQueue.prototype.isEmpty = function () {\r\n return !this.first;\r\n};\r\n\r\nvar a = [];\r\nvar q = new Queue();\r\n\r\n\r\nclass Queue2 {\r\n constructor() {\r\n this.list = new Set();\r\n }\r\n\r\n enqueue(value) {\r\n this.list.add({value});\r\n }\r\n\r\n dequeue() {\r\n for (let item of this.list) {\r\n this.list.delete(item);\r\n return item.value;\r\n }\r\n }\r\n\r\n isEmpty() {\r\n return this.list.size === 0;\r\n }\r\n}\r\n\r\nvar q2 = new Queue2();","TestCases":[{"Name":"array","Code":"for (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n a.push(i);\r\n}\r\nwhile (a.length) {\r\n var x = a.shift();\r\n}","IsDeferred":false},{"Name":"queue","Code":"for (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n q.enqueue(i);\r\n}\r\nwhile (!q.isEmpty()) {\r\n var x = q.dequeue();\r\n}","IsDeferred":false},{"Name":"array non-destructive","Code":"for (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n a.push(i);\r\n}\r\nfor (var i = 0, len = a.length; i \u003C len; i\u002B\u002B) {\r\n var x = a[i];\r\n}\r\na = [];","IsDeferred":false},{"Name":"queue2","Code":"for (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n q2.enqueue(i);\r\n}\r\nwhile (!q2.isEmpty()) {\r\n var x = q2.dequeue();\r\n}","IsDeferred":false}]}