6 description: Contains Array Prototypes like each, contains, and erase.
8 license: MIT-style license.
20 every: function(fn, bind){
21 for (var i = 0, l = this.length >>> 0; i < l; i++){
22 if ((i in this) && !fn.call(bind, this[i], i, this)) return false;
27 filter: function(fn, bind){
29 for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){
31 if (fn.call(bind, value, i, this)) results.push(value);
36 indexOf: function(item, from){
37 var length = this.length >>> 0;
38 for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
39 if (this[i] === item) return i;
44 map: function(fn, bind){
45 var length = this.length >>> 0, results = Array(length);
46 for (var i = 0; i < length; i++){
47 if (i in this) results[i] = fn.call(bind, this[i], i, this);
52 some: function(fn, bind){
53 for (var i = 0, l = this.length >>> 0; i < l; i++){
54 if ((i in this) && fn.call(bind, this[i], i, this)) return true;
61 return this.filter(function(item){
66 invoke: function(methodName){
67 var args = Array.slice(arguments, 1);
68 return this.map(function(item){
69 return item[methodName].apply(item, args);
73 associate: function(keys){
74 var obj = {}, length = Math.min(this.length, keys.length);
75 for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
79 link: function(object){
81 for (var i = 0, l = this.length; i < l; i++){
82 for (var key in object){
83 if (object[key](this[i])){
84 result[key] = this[i];
93 contains: function(item, from){
94 return this.indexOf(item, from) != -1;
97 append: function(array){
98 this.push.apply(this, array);
103 return (this.length) ? this[this.length - 1] : null;
106 getRandom: function(){
107 return (this.length) ? this[Number.random(0, this.length - 1)] : null;
110 include: function(item){
111 if (!this.contains(item)) this.push(item);
115 combine: function(array){
116 for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
120 erase: function(item){
121 for (var i = this.length; i--;){
122 if (this[i] === item) this.splice(i, 1);
134 for (var i = 0, l = this.length; i < l; i++){
135 var type = typeOf(this[i]);
136 if (type == 'null') continue;
137 array = array.concat((type == 'array' || type == 'collection' || type == 'arguments' || instanceOf(this[i], Array)) ? Array.flatten(this[i]) : this[i]);
143 for (var i = 0, l = this.length; i < l; i++){
144 if (this[i] != null) return this[i];
149 hexToRgb: function(array){
150 if (this.length != 3) return null;
151 var rgb = this.map(function(value){
152 if (value.length == 1) value += value;
153 return parseInt(value, 16);
155 return (array) ? rgb : 'rgb(' + rgb + ')';
158 rgbToHex: function(array){
159 if (this.length < 3) return null;
160 if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
162 for (var i = 0; i < 3; i++){
163 var bit = (this[i] - 0).toString(16);
164 hex.push((bit.length == 1) ? '0' + bit : bit);
166 return (array) ? hex : '#' + hex.join('');
173 Array.alias('extend', 'append');
175 var $pick = this.$pick = function(){
176 return Array.from(arguments).pick();