+var STABLE_SORT = !fails(function () {
+ // feature detection can be too slow, so check engines versions
+ if (V8) return V8 < 70;
+ if (FF && FF > 3) return;
+ if (IE_OR_EDGE) return true;
+ if (WEBKIT) return WEBKIT < 603;
+
+ var result = '';
+ var code, chr, value, index;
+
+ // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
+ for (code = 65; code < 76; code++) {
+ chr = String.fromCharCode(code);
+
+ switch (code) {
+ case 66: case 69: case 70: case 72: value = 3; break;
+ case 68: case 71: value = 4; break;
+ default: value = 2;
+ }
+
+ for (index = 0; index < 47; index++) {
+ test.push({ k: chr + index, v: value });
+ }
+ }
+
+ test.sort(function (a, b) { return b.v - a.v; });
+
+ for (index = 0; index < test.length; index++) {
+ chr = test[index].k.charAt(0);
+ if (result.charAt(result.length - 1) !== chr) result += chr;
+ }
+
+ return result !== 'DGBEFHACIJK';
+});
+
+var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
+
+var getSortCompare = function (comparefn) {
+ return function (x, y) {
+ if (y === undefined) return -1;
+ if (x === undefined) return 1;
+ if (comparefn !== undefined) return +comparefn(x, y) || 0;
+ return toString(x) > toString(y) ? 1 : -1;
+ };
+};