{"ScriptPreparationCode":"var sampleData = [];\r\nfor (var i=0; i \u003C 100000; i\u002B\u002B){ \r\n sampleData.push({value: (Math.floor(Math.random() * 10000))});\r\n}\r\n\r\nvar selectorFn = function(x) { \r\n return x.value; \r\n}\r\n\r\nvar combSort = function (source, selectorFn, sortDirection) {\r\n var result = source.slice();\r\n var count = result.length;\r\n var gap = count;\r\n var swapped = true;\r\n\r\n while (gap \u003E 1 || swapped) {\r\n\r\n if (gap \u003E 1) {\r\n gap = Math.floor(gap / 1.24733);\r\n }\r\n\r\n var i = 0;\r\n swapped = false;\r\n\r\n while ((i \u002B gap) \u003C count) {\r\n\r\n var item1 = result[i];\r\n var item2 = result[i \u002B gap];\r\n\r\n if (shouldBeSwaped(selectorFn(item1), selectorFn(item2), selectorFn, sortDirection)) {\r\n result[i] = item2;\r\n result[i \u002B gap] = item1;\r\n swapped = true;\r\n }\r\n\r\n i\u002B\u002B;\r\n }\r\n\t}\r\n \r\n return result;\r\n}\r\n\r\n var shouldBeSwaped = function(value, valueToCompare, selectorFn, sortDirection) {\r\n \tvar less = value \u003E valueToCompare;\r\n\treturn sortDirection === \u0022asc\u0022 ? less : !less;\r\n }","TestCases":[{"Name":"Native Sort DESC","Code":"var order = \u0022desc\u0022;\r\n\r\nsampleData.sort(function(a,b){\r\n\tvar x = selectorFn(a); var y = selectorFn(b);\r\n\tvar res = ((x \u003C y) ? -1 : ((x \u003E y) ? 1 : 0));\r\n\r\n\treturn order === \u0022desc\u0022 ? -1*res : res;\r\n})","IsDeferred":false},{"Name":"Native Sort ASC","Code":"var order = \u0022desc\u0022;\r\n\r\nsampleData.sort(function(a,b){\r\n\tvar x = selectorFn(a); var y = selectorFn(b);\r\n\tvar res = ((x \u003C y) ? -1 : ((x \u003E y) ? 1 : 0));\r\n\r\n\treturn order === \u0022desc\u0022 ? -1*res : res;\r\n})","IsDeferred":false},{"Name":"Comb Sort DESC","Code":"var order = \u0022asc\u0022;\r\n\r\ncombSort(sampleData, selectorFn, order);","IsDeferred":false},{"Name":"Comb Sort ASC","Code":"var order = \u0022asc\u0022;\r\n\r\ncombSort(sampleData, selectorFn, order);","IsDeferred":false}]}