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.typed-array.sort.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
  3. var global = require('../internals/global');
  4. var fails = require('../internals/fails');
  5. var aFunction = require('../internals/a-function');
  6. var toLength = require('../internals/to-length');
  7. var internalSort = require('../internals/array-sort');
  8. var FF = require('../internals/engine-ff-version');
  9. var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge');
  10. var V8 = require('../internals/engine-v8-version');
  11. var WEBKIT = require('../internals/engine-webkit-version');
  12. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  13. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  14. var Uint16Array = global.Uint16Array;
  15. var nativeSort = Uint16Array && Uint16Array.prototype.sort;
  16. // WebKit
  17. var ACCEPT_INCORRECT_ARGUMENTS = !!nativeSort && !fails(function () {
  18. var array = new Uint16Array(2);
  19. array.sort(null);
  20. array.sort({});
  21. });
  22. var STABLE_SORT = !!nativeSort && !fails(function () {
  23. // feature detection can be too slow, so check engines versions
  24. if (V8) return V8 < 74;
  25. if (FF) return FF < 67;
  26. if (IE_OR_EDGE) return true;
  27. if (WEBKIT) return WEBKIT < 602;
  28. var array = new Uint16Array(516);
  29. var expected = Array(516);
  30. var index, mod;
  31. for (index = 0; index < 516; index++) {
  32. mod = index % 4;
  33. array[index] = 515 - index;
  34. expected[index] = index - 2 * mod + 3;
  35. }
  36. array.sort(function (a, b) {
  37. return (a / 4 | 0) - (b / 4 | 0);
  38. });
  39. for (index = 0; index < 516; index++) {
  40. if (array[index] !== expected[index]) return true;
  41. }
  42. });
  43. var getSortCompare = function (comparefn) {
  44. return function (x, y) {
  45. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  46. // eslint-disable-next-line no-self-compare -- NaN check
  47. if (y !== y) return -1;
  48. // eslint-disable-next-line no-self-compare -- NaN check
  49. if (x !== x) return 1;
  50. if (x === 0 && y === 0) return 1 / x > 0 && 1 / y < 0 ? 1 : -1;
  51. return x > y;
  52. };
  53. };
  54. // `%TypedArray%.prototype.sort` method
  55. // https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort
  56. exportTypedArrayMethod('sort', function sort(comparefn) {
  57. var array = this;
  58. if (comparefn !== undefined) aFunction(comparefn);
  59. if (STABLE_SORT) return nativeSort.call(array, comparefn);
  60. aTypedArray(array);
  61. var arrayLength = toLength(array.length);
  62. var items = Array(arrayLength);
  63. var index;
  64. for (index = 0; index < arrayLength; index++) {
  65. items[index] = array[index];
  66. }
  67. items = internalSort(array, getSortCompare(comparefn));
  68. for (index = 0; index < arrayLength; index++) {
  69. array[index] = items[index];
  70. }
  71. return array;
  72. }, !STABLE_SORT || ACCEPT_INCORRECT_ARGUMENTS);