Requires

Provides

Contains Array Prototypes like each, contains, and erase.

License:
MIT-style license.
  1. 18
  2. 19
  3. 20
  4. 21
  5. 22
  6. 23
  7. 24
  8. 25
  9. 26
  10. 27
  11. 28
  12. 29
  13. 30
  14. 31
  15. 32
  16. 33
  17. 34
  18. 35
  19. 36
  20. 37
  21. 38
  22. 39
  23. 40
  24. 41
  25. 42
  26. 43
  27. 44
  28. 45
  29. 46
  30. 47
  31. 48
  32. 49
  33. 50
  34. 51
  35. 52
  36. 53
  37. 54
  38. 55
  39. 56
  40. 57
  41. 58
  42. 59
  43. 60
  44. 61
  45. 62
  46. 63
  47. 64
  48. 65
  49. 66
  50. 67
  51. 68
  52. 69
  53. 70
  54. 71
  55. 72
  56. 73
  57. 74
  58. 75
  59. 76
  60. 77
  61. 78
  62. 79
  63. 80
  64. 81
  65. 82
  66. 83
  67. 84
  68. 85
  69. 86
  70. 87
  71. 88
  72. 89
  73. 90
  74. 91
  75. 92
  76. 93
  77. 94
  78. 95
  79. 96
  80. 97
  81. 98
  82. 99
  83. 100
  84. 101
  85. 102
  86. 103
  87. 104
  88. 105
  89. 106
  90. 107
  91. 108
  92. 109
  93. 110
  94. 111
  95. 112
  96. 113
  97. 114
  98. 115
  99. 116
  100. 117
  101. 118
  102. 119
  103. 120
  104. 121
  105. 122
  106. 123
  107. 124
  108. 125
  109. 126
  110. 127
  111. 128
  112. 129
  113. 130
  114. 131
  115. 132
  116. 133
  117. 134
  118. 135
  119. 136
  120. 137
  121. 138
  122. 139
  123. 140
  124. 141
  125. 142
  126. 143
  127. 144
  128. 145
  129. 146
  130. 147
  131. 148
  132. 149
  133. 150
  134. 151
  135. 152
  136. 153
  137. 154
  138. 155
  139. 156
  140. 157
  141. 158
  142. 159
  143. 160
  144. 161
  145. 162
  146. 163
  147. 164
  148. 165
  149. 166
  150. 167
Array.implement({ invoke: function(methodName){ var args = Array.slice(arguments, 1); return this.map(function(item){ return item[methodName].apply(item, args); }); }, every: function(fn, bind){ for (var i = 0, l = this.length; i < l; i++){ if ((i in this) && !fn.call(bind, this[i], i, this)) return false; } return true; }, filter: function(fn, bind){ var results = []; for (var i = 0, l = this.length; i < l; i++){ if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]); } return results; }, clean: function(){ return this.filter(function(item){ return item != null; }); }, indexOf: function(item, from){ var len = this.length; for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){ if (this[i] === item) return i; } return -1; }, map: function(fn, bind){ var results = []; for (var i = 0, l = this.length; i < l; i++){ if (i in this) results[i] = fn.call(bind, this[i], i, this); } return results; }, some: function(fn, bind){ for (var i = 0, l = this.length; i < l; i++){ if ((i in this) && fn.call(bind, this[i], i, this)) return true; } return false; }, associate: function(keys){ var obj = {}, length = Math.min(this.length, keys.length); for (var i = 0; i < length; i++) obj[keys[i]] = this[i]; return obj; }, link: function(object){ var result = {}; for (var i = 0, l = this.length; i < l; i++){ for (var key in object){ if (object[key](this[i])){ result[key] = this[i]; delete object[key]; break; } } } return result; }, contains: function(item, from){ return this.indexOf(item, from) != -1; }, append: function(array){ this.push.apply(this, array); return this; }, getLast: function(){ return (this.length) ? this[this.length - 1] : null; }, getRandom: function(){ return (this.length) ? this[Number.random(0, this.length - 1)] : null; }, include: function(item){ if (!this.contains(item)) this.push(item); return this; }, combine: function(array){ for (var i = 0, l = array.length; i < l; i++) this.include(array[i]); return this; }, erase: function(item){ for (var i = this.length; i--;){ if (this[i] === item) this.splice(i, 1); } return this; }, empty: function(){ this.length = 0; return this; }, flatten: function(){ var array = []; for (var i = 0, l = this.length; i < l; i++){ var type = typeOf(this[i]); if (type == 'null') continue; array = array.concat((type == 'array' || type == 'collection' || type == 'arguments' || instanceOf(this[i], Array)) ? Array.flatten(this[i]) : this[i]); } return array; }, pick: function(){ for (var i = 0, l = this.length; i < l; i++){ if (this[i] != null) return this[i]; } return null; }, hexToRgb: function(array){ if (this.length != 3) return null; var rgb = this.map(function(value){ if (value.length == 1) value += value; return value.toInt(16); }); return (array) ? rgb : 'rgb(' + rgb + ')'; }, rgbToHex: function(array){ if (this.length < 3) return null; if (this.length == 4 && this[3] == 0 && !array) return 'transparent'; var hex = []; for (var i = 0; i < 3; i++){ var bit = (this[i] - 0).toString(16); hex.push((bit.length == 1) ? '0' + bit : bit); } return (array) ? hex : '#' + hex.join(''); } });

<1.2compat>

  1. 171
  2. 172
  3. 173
  4. 174
  5. 175
Array.alias('extend', 'append'); var $pick = function(){ return Array.from(arguments).pick(); };

</1.2compat>