{"ScriptPreparationCode":"var arr = [{\r\n name: \u0022\u0412\u0430\u043D\u044F\u0022,\r\n date: \u00222024-12-01 18:00\u0022,\r\n curr: \u0022RUB\u0022,\r\n level: 12,\r\n},\r\n{\r\n name: \u0022\u041C\u0430\u043D\u044F\u0022,\r\n date: \u00222024-12-01 02:00\u0022,\r\n curr: \u0022KZT\u0022,\r\n level: 3,\r\n},\r\n{\r\n name: \u0022\u041F\u0435\u0442\u044F\u0022,\r\n date: \u00222024-12-01 12:00\u0022,\r\n curr: \u0022USD\u0022,\r\n level: 7,\r\n},\r\n{\r\n name: \u0022\u0412\u0438\u043A\u0430\u0022,\r\n date: \u00222024-12-01 05:00\u0022,\r\n curr: \u0022RUB\u0022,\r\n level: 9,\r\n},\r\n{\r\n name: \u0022\u041B\u0435\u0440\u0430\u0022,\r\n date: \u00222024-12-01 11:00\u0022,\r\n curr: \u0022RUB\u0022,\r\n level: 2,\r\n},\r\n{\r\n name: \u0022\u041A\u0430\u0448\u0430\u0022,\r\n date: \u00222024-12-01 15:00\u0022,\r\n curr: \u0022KZT\u0022,\r\n level: 10,\r\n},\r\n{\r\n name: \u0022\u041F\u0430\u0448\u0430\u0022,\r\n date: \u00222024-12-01 17:00\u0022,\r\n curr: \u0022USD\u0022,\r\n level: 1,\r\n},\r\n{\r\n name: \u0022\u0414\u0430\u0448\u0430\u0022,\r\n date: \u00222024-12-01 10:00\u0022,\r\n curr: \u0022RUB\u0022,\r\n level: 8,\r\n},\r\n{\r\n name: \u0022\u0412\u0435\u0440\u0430\u0022,\r\n date: \u00222024-12-01 00:00\u0022,\r\n curr: \u0022RUB\u0022,\r\n level: 5,\r\n},\r\n{\r\n name: \u0022\u0421\u0430\u0448\u0430\u0022,\r\n date: \u00222024-12-01 14:00\u0022,\r\n curr: \u0022USD\u0022,\r\n level: 11,\r\n},\r\n{\r\n name: \u0022\u041C\u0430\u0448\u0430\u0022,\r\n date: \u00222024-12-01 10:00\u0022,\r\n curr: \u0022KZT\u0022,\r\n level: 4,\r\n},\r\n{\r\n name: \u0022\u0412\u0430\u043D\u044F\u0022,\r\n date: \u00222024-12-01 15:00\u0022,\r\n curr: \u0022USD\u0022,\r\n level: 6,\r\n},\r\n];\r\n\r\nvar CURR_ORDER = {\r\n RUB: 1,\r\n USD: 2,\r\n KZT: 3,\r\n};\r\n\r\nvar CONDITIONS = [\r\n (a, b) =\u003E CURR_ORDER[a.curr] - CURR_ORDER[b.curr],\r\n (a, b) =\u003E new Date(a.date) - new Date(b.date),\r\n];\r\n\r\nvar compare = (conditions) =\u003E (a, b) =\u003E {\r\n for (let i = 0; i \u003C conditions.length; i\u002B\u002B) {\r\n const condition = conditions[i];\r\n const type = typeof condition;\r\n if (type === \u0022string\u0022) {\r\n if (typeof a[condition] === \u0022string\u0022) {\r\n const result = a[condition].localeCompare(b[condition]);\r\n if (!result) continue;\r\n return result;\r\n } else if (typeof a[condition] === \u0022number\u0022) {\r\n const result = a[condition] - b[condition];\r\n if (!result) continue;\r\n return result;\r\n }\r\n } else if (type === \u0022function\u0022) {\r\n const result = condition(a, b);\r\n if (!result) continue;\r\n return result;\r\n }\r\n }\r\n\r\n return 0;\r\n};\r\n\r\nvar stdSort = (arr, conditions) =\u003E {\r\n const newArr = [...arr];\r\n newArr.sort(compare);\r\n return newArr;\r\n};\r\n\r\nvar insertionSort = (arr, conditions) =\u003E {\r\n const newArr = [...arr];\r\n\r\n for (let i = 1, l = newArr.length; i \u003C l; i\u002B\u002B) {\r\n const current = arr[i];\r\n let j = i;\r\n const comp = compare(conditions);\r\n while (j \u003E 0 \u0026\u0026 comp(newArr[j - 1], current)) {\r\n newArr[j] = newArr[j - 1];\r\n j--;\r\n }\r\n newArr[j] = current;\r\n }\r\n return newArr;\r\n};\r\n\r\nvar partition = (arr, start, end, compare) =\u003E {\r\n const pivotValue = arr[end];\r\n let pivotIndex = start;\r\n\r\n\r\n for (let i = start; i \u003C end; i\u002B\u002B) {\r\n if (compare(arr[i], pivotValue) \u003C 0) {\r\n [arr[i], arr[pivotIndex]] = [arr[pivotIndex], arr[i]];\r\n pivotIndex\u002B\u002B;\r\n }\r\n }\r\n\r\n [arr[pivotIndex], arr[end]] = [arr[end], arr[pivotIndex]];\r\n return pivotIndex;\r\n};\r\n\r\nvar quickSortIterative = (arr, conditions) =\u003E {\r\n const newArr = [...arr];\r\n const stack = [0, arr.length - 1];\r\n const comp = compare(conditions);\r\n\r\n while (stack[stack.length - 1] \u003E= 0) {\r\n end = stack.pop();\r\n start = stack.pop();\r\n\r\n pivotIndex = partition(newArr, start, end, comp);\r\n\r\n if (pivotIndex - 1 \u003E start) {\r\n stack.push(start);\r\n stack.push(pivotIndex - 1);\r\n }\r\n\r\n if (pivotIndex \u002B 1 \u003C end) {\r\n stack.push(pivotIndex \u002B 1);\r\n stack.push(end);\r\n }\r\n }\r\n\r\n return newArr;\r\n};","TestCases":[{"Name":"Lodash_4.17.21.sortBy","Code":"_.sortBy(arr, [(o) =\u003E CURR_ORDER[o.curr], (o) =\u003E new Date(o.date)]);","IsDeferred":false},{"Name":"stdSort","Code":"stdSort(arr, CONDITIONS);","IsDeferred":false},{"Name":"InsertionSort","Code":"insertionSort(arr, CONDITIONS);","IsDeferred":false},{"Name":"QuickSort","Code":"quickSortIterative(arr, CONDITIONS);","IsDeferred":false}]}