{"ScriptPreparationCode":"/**\r\n * Convenience method to create nodes\r\n * @param data\r\n * @param next\r\n * @return {{data: *, next: *}}\r\n */\r\nfunction createNode(data, next) {\r\n return {\r\n data: data,\r\n next\r\n };\r\n}\r\n\r\n/**\r\n * Determines whether or not the list is empty\r\n * @param head\r\n * @return {boolean}\r\n */\r\nfunction isEmptyList(head) {\r\n return head === null;\r\n}\r\n\r\n/**\r\n * Linked List base on code by Nicholas C Zakas. Additional modifications are my own.\r\n */\r\nfunction LinkedList() {\r\n this._size = 0;\r\n this._head = null;\r\n this._tail = null;\r\n}\r\n\r\nLinkedList.prototype = {\r\n \r\n //restore constructor\r\n constructor: LinkedList,\r\n \r\n /**\r\n * Like its array counterpart, unshift appends an item to the beginning of the list\r\n * @param data\r\n */\r\n unshift: function unshift(data) {\r\n const node = createNode(data);\r\n\r\n //special case: no items in the list yet\r\n if (isEmptyList(this._head)) {\r\n this._head = node;\r\n } else {\r\n node.next = this._head;\r\n this._head = node;\r\n }\r\n \u002B\u002Bthis._size;\r\n },\r\n\r\n /**\r\n * Returns the size of the list\r\n * @return {number}\r\n */\r\n size: function size() {\r\n return this._size;\r\n },\r\n\r\n /**\r\n * Applies a function to each item in the list\r\n * @param fn\r\n */\r\n forEach: function forEach(fn) {\r\n if (this._size \u003E 0) {\r\n let current = this._head;\r\n let index = 0;\r\n\r\n while (current) {\r\n fn(current.data, index, this);\r\n \u002B\u002Bindex;\r\n current = current.next;\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction domUpdater(requestList) {\r\n let batch = document.createDocumentFragment();\r\n const list = document.getElementById(\u0022request-list\u0022);\r\n \r\n requestList.forEach(function(request) {\r\n const li = document.createElement(\u0022li\u0022);\r\n li.dataset.id = request.id;\r\n li.textContent = request.details;\r\n batch.appendChild(li);\r\n });\r\n\r\n list.appendChild(batch);\r\n}\r\n\r\nfunction createRequest(num) {\r\n return {\r\n id: num,\r\n details: \u0022details for: \u0022 \u002B num\r\n };\r\n}\r\n","TestCases":[{"Name":"Linked List","Code":"const requests = new LinkedList();\r\nlet count = 500;\r\n\r\nwhile(count--) {\r\n requests.unshift(createRequest(count));\r\n}\r\n\r\ndomUpdater(requests);\r\n","IsDeferred":false},{"Name":"Array","Code":"const requests = [];\r\nlet count = 500;\r\n\r\nwhile(count--) {\r\n requests.unshift(createRequest(count));\r\n}\r\n\r\ndomUpdater(requests);","IsDeferred":false}]}