{"ScriptPreparationCode":"const randomStDate = () =\u003E {\r\n const randD = new Date(new Date(\u00222021-12-05\u0022).getTime() \u002B Math.random() * (new Date(\u00222026-12-05\u0022).getTime() - new Date(\u00222023-12-05\u0022).getTime()))\r\n let month = \u0027\u0027 \u002B (randD.getMonth() \u002B 1);\r\n let day = \u0027\u0027 \u002B randD.getDate();\r\n let year = randD.getFullYear();\r\n if (month.length \u003C 2) month = \u00270\u0027 \u002B month;\r\n if (day.length \u003C 2) day = \u00270\u0027 \u002B day;\r\n return [year, month, day].join(\u0027-\u0027);\r\n\r\n};\r\n\r\nconst rndId = Math.floor(Math.random() * (100000000 - 1 \u002B 1) \u002B 1)\r\n\r\nconst createArr = () =\u003E {\r\n let workArr = []\r\n for (let i = 0; i \u003C 1000; i\u002B\u002B) {\r\n const pl = {\r\n tisId: rndId,\r\n startDate: randomStDate(),\r\n endDate: randomStDate(),\r\n site: \u0022Liverpool\u0022,\r\n }\r\n workArr.push(pl)\r\n\r\n }\r\n return workArr\r\n}\r\n\r\nvar workArr = createArr()","TestCases":[{"Name":"loop","Code":"\r\n\tlet pastArr = [];\r\n let futureArr = [];\r\n\r\n for (let i = 0; i \u003C workArr.length; i\u002B\u002B) {\r\n const pl = workArr[i];\r\n const futPl = futureArr[0];\r\n if (new Date() \u003E new Date(pl.startDate)) {\r\n pastArr = [...pastArr, pl];\r\n } else {\r\n if (futureArr.length \u003C 1) {\r\n futureArr = [pl];\r\n } else if (new Date(pl.startDate) \u003C new Date(futPl.startDate)) {\r\n futureArr = [pl];\r\n } else if (pl.startDate === futPl.startDate) {\r\n futureArr = [...futureArr, pl];\r\n }\r\n }\r\n }\r\n return [...pastArr, ...futureArr];\r\n\r\n\r\n\r\n","IsDeferred":false},{"Name":"chained array","Code":"const today = new Date().toISOString().slice(0,10)\r\n\r\n const firstFutureWorks = workArr\r\n .filter(w =\u003E w.startDate \u003E today)\r\n .sort((a, b) =\u003E (a.startDate \u003E b.startDate ? 1 : -1));\r\n\r\n const nextFutureDate = firstFutureWorks[0]\r\n ? firstFutureWorks[0].startDate\r\n : today;\r\n\r\nreturn workArr.filter(w =\u003E w.startDate \u003C= nextFutureDate);\r\n","IsDeferred":false}]}