{"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: \u00222026-12-05\u0022,\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()\r\nvar today = new Date().toISOString().slice(0, 10)","TestCases":[{"Name":"for loop","Code":"let pastArr = [];\r\nlet futureArr = [];\r\n\r\n for (let i = 0; i \u003C workArr.length; i\u002B\u002B) {\r\n const pl = workArr[i];\r\n switch(true){\r\n case pl.startDate \u003C today :\r\n\t pastArr.push(pl);\r\n break;\r\n case futureArr.length \u003C 1 \u0026\u0026 pl.startDate \u003E= today :\r\n\t futureArr = [pl];\r\n break;\r\n case futureArr.length \u003E 0 \u0026\u0026 pl.startDate \u003C futureArr[0].startDate :\r\n\t futureArr = [pl];\r\n break;\r\n case futureArr.length \u003E 0 \u0026\u0026 pl.startDate === futureArr[0].startDate :\r\n futureArr.push(pl);\r\n break;\r\n }\r\n }\r\nreturn [...pastArr, ...futureArr].sort((a, b) =\u003E (a.startDate \u003E b.startDate ? 1 : -1));","IsDeferred":false},{"Name":"chained arr","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);","IsDeferred":false}]}