Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

es.array.sort.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var aFunction = require('../internals/a-function');
  4. var toObject = require('../internals/to-object');
  5. var toLength = require('../internals/to-length');
  6. var fails = require('../internals/fails');
  7. var internalSort = require('../internals/array-sort');
  8. var arrayMethodIsStrict = require('../internals/array-method-is-strict');
  9. var FF = require('../internals/engine-ff-version');
  10. var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
  11. var V8 = require('../internals/engine-v8-version');
  12. var WEBKIT = require('../internals/engine-webkit-version');
  13. var test = [];
  14. var nativeSort = test.sort;
  15. // IE8-
  16. var FAILS_ON_UNDEFINED = fails(function () {
  17. test.sort(undefined);
  18. });
  19. // V8 bug
  20. var FAILS_ON_NULL = fails(function () {
  21. test.sort(null);
  22. });
  23. // Old WebKit
  24. var STRICT_METHOD = arrayMethodIsStrict('sort');
  25. var STABLE_SORT = !fails(function () {
  26. // feature detection can be too slow, so check engines versions
  27. if (V8) return V8 < 70;
  28. if (FF && FF > 3) return;
  29. if (IE_OR_EDGE) return true;
  30. if (WEBKIT) return WEBKIT < 603;
  31. var result = '';
  32. var code, chr, value, index;
  33. // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
  34. for (code = 65; code < 76; code++) {
  35. chr = String.fromCharCode(code);
  36. switch (code) {
  37. case 66: case 69: case 70: case 72: value = 3; break;
  38. case 68: case 71: value = 4; break;
  39. default: value = 2;
  40. }
  41. for (index = 0; index < 47; index++) {
  42. test.push({ k: chr + index, v: value });
  43. }
  44. }
  45. test.sort(function (a, b) { return b.v - a.v; });
  46. for (index = 0; index < test.length; index++) {
  47. chr = test[index].k.charAt(0);
  48. if (result.charAt(result.length - 1) !== chr) result += chr;
  49. }
  50. return result !== 'DGBEFHACIJK';
  51. });
  52. var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
  53. var getSortCompare = function (comparefn) {
  54. return function (x, y) {
  55. if (y === undefined) return -1;
  56. if (x === undefined) return 1;
  57. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  58. return String(x) > String(y) ? 1 : -1;
  59. };
  60. };
  61. // `Array.prototype.sort` method
  62. // https://tc39.es/ecma262/#sec-array.prototype.sort
  63. $({ target: 'Array', proto: true, forced: FORCED }, {
  64. sort: function sort(comparefn) {
  65. if (comparefn !== undefined) aFunction(comparefn);
  66. var array = toObject(this);
  67. if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
  68. var items = [];
  69. var arrayLength = toLength(array.length);
  70. var itemsLength, index;
  71. for (index = 0; index < arrayLength; index++) {
  72. if (index in array) items.push(array[index]);
  73. }
  74. items = internalSort(items, getSortCompare(comparefn));
  75. itemsLength = items.length;
  76. index = 0;
  77. while (index < itemsLength) array[index] = items[index++];
  78. while (index < arrayLength) delete array[index++];
  79. return array;
  80. }
  81. });