Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

130 řádky
2.1 KiB

  1. /* global _, scale, scaleMult */
  2. window.scale = 40;
  3. window.scaleMult = 5;
  4. //eslint-disable-next-line no-extend-native
  5. Array.prototype.firstIndex = function (callback, thisArg) {
  6. let T = thisArg;
  7. let O = Object(this);
  8. let len = O.length >>> 0;
  9. let k = 0;
  10. while (k < len) {
  11. let kValue;
  12. if (k in O) {
  13. kValue = O[k];
  14. if (callback.call(T, kValue, k, O))
  15. return k;
  16. }
  17. k++;
  18. }
  19. return -1;
  20. };
  21. //eslint-disable-next-line no-extend-native
  22. Array.prototype.spliceWhere = function (callback, thisArg) {
  23. let T = thisArg;
  24. let O = Object(this);
  25. let len = O.length >>> 0;
  26. let k = 0;
  27. while (k < len) {
  28. let kValue;
  29. if (k in O) {
  30. kValue = O[k];
  31. if (callback.call(T, kValue, k, O)) {
  32. O.splice(k, 1);
  33. k--;
  34. }
  35. }
  36. k++;
  37. }
  38. };
  39. //eslint-disable-next-line no-extend-native
  40. Array.prototype.spliceFirstWhere = function (callback, thisArg) {
  41. let T = thisArg;
  42. let O = Object(this);
  43. let len = O.length >>> 0;
  44. let k = 0;
  45. while (k < len) {
  46. let kValue;
  47. if (k in O) {
  48. kValue = O[k];
  49. if (callback.call(T, kValue, k, O)) {
  50. O.splice(k, 1);
  51. return kValue;
  52. }
  53. }
  54. k++;
  55. }
  56. };
  57. //eslint-disable-next-line no-extend-native
  58. Object.defineProperty(Object.prototype, 'has', {
  59. enumerable: false,
  60. value: function (prop) {
  61. //eslint-disable-next-line no-undefined
  62. return (this.hasOwnProperty(prop) && this[prop] !== undefined && this[prop] !== null);
  63. }
  64. });
  65. window._ = {
  66. create: function () {
  67. let result = {};
  68. [].slice.call(arguments).forEach(function (a) {
  69. $.extend(true, result, a);
  70. });
  71. return result;
  72. },
  73. get2dArray: function (w, h, def) {
  74. def = def || 0;
  75. let result = [];
  76. for (let i = 0; i < w; i++) {
  77. let inner = [];
  78. for (let j = 0; j < h; j++) {
  79. if (def === 'array')
  80. inner.push([]);
  81. else
  82. inner.push(def);
  83. }
  84. result.push(inner);
  85. }
  86. return result;
  87. },
  88. randWeighted: function (weights) {
  89. let sample = [];
  90. weights.forEach(function (w, i) {
  91. for (let j = 0; j < w; j++)
  92. sample.push(i);
  93. });
  94. return sample[~~(Math.random() * sample.length)];
  95. }
  96. };
  97. define([
  98. ], function (
  99. ) {
  100. return window._;
  101. });