{"ScriptPreparationCode":null,"TestCases":[{"Name":"forEach Push","Code":"const forEachTest = (nthElements, excludeBeforeElements, excludeAfterElements) =\u003E {\r\n const daiContainers = [];\r\n nthElements.forEach((nthElement) =\u003E {\r\n // Check if we should exclude this element due to the element before / after\r\n const nextElement = nthElement.nextElementSibling;\r\n // If this nthElement is one we shouldn\u0027t come AFTER\r\n // or the NEXT element is the one we shouldn\u0027t come BEFORE\r\n // then return (being explicit here for clarity)\r\n if (\r\n excludeAfterElements.includes(nthElement)\r\n || excludeBeforeElements.includes(nextElement)\r\n ) {\r\n return;\r\n }\r\n\r\n const daiContainerElement = document.createElement(\u0027div\u0027);\r\n daiContainerElement.setAttribute(\u0027class\u0027, \u0027test-class\u0027);\r\n nthElement.after(daiContainerElement);\r\n daiContainers.push(daiContainerElement);\r\n });\r\n return daiContainers;\r\n}\r\n\r\nconst nthElements = Array.from(document.querySelectorAll(\u0027ul li\u0027));\r\nconst excludeBeforeElements = Array.from(document.querySelectorAll(\u0027ul a\u0027));\r\nconst excludeAfterElements = [];\r\n\r\nconst containers = forEachTest(nthElements, excludeBeforeElements, excludeAfterElements);","IsDeferred":false},{"Name":"reduce","Code":"const reduceTest = (nthElements, excludeBeforeElements, excludeAfterElements) =\u003E {\r\n return nthElements.reduce((daiContainers, nthElement) =\u003E {\r\n const nextElement = nthElement?.nextElementSibling;\r\n // Skip insertion if nthElement or its next sibling is excluded\r\n if (excludeAfterElements.includes(nthElement) || excludeBeforeElements.includes(nextElement)) {\r\n return daiContainers;\r\n }\r\n // Create and insert ad container\r\n const daiContainerElement = document.createElement(\u0027div\u0027);\r\n daiContainerElement.setAttribute(\u0027class\u0027, \u0027test-class\u0027);\r\n nthElement.after(daiContainerElement);\r\n daiContainers.push(daiContainerElement);\r\n return daiContainers;\r\n }, []); \r\n}\r\n \r\nconst nthElements = Array.from(document.querySelectorAll(\u0027ul li\u0027));\r\nconst excludeBeforeElements = Array.from(document.querySelectorAll(\u0027ul a\u0027));\r\nconst excludeAfterElements = [];\r\n\r\nconst containers = reduceTest(nthElements, excludeBeforeElements, excludeAfterElements);","IsDeferred":false}]}