3 Contains Array Prototypes like each, contains, and erase.
11 every: function(fn, bind){
12 for (var i = 0, l = this.length; i < l; i++){
13 if (!fn.call(bind, this[i], i, this)) return false;
18 filter: function(fn, bind){
20 for (var i = 0, l = this.length; i < l; i++){
21 if (fn.call(bind, this[i], i, this)) results.push(this[i]);
27 return this.filter($defined);
30 indexOf: function(item, from){
31 var len = this.length;
32 for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
33 if (this[i] === item) return i;
38 map: function(fn, bind){
40 for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this);
44 some: function(fn, bind){
45 for (var i = 0, l = this.length; i < l; i++){
46 if (fn.call(bind, this[i], i, this)) return true;
51 associate: function(keys){
52 var obj = {}, length = Math.min(this.length, keys.length);
53 for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
57 link: function(object){
59 for (var i = 0, l = this.length; i < l; i++){
60 for (var key in object){
61 if (object[key](this[i])){
62 result[key] = this[i];
71 contains: function(item, from){
72 return this.indexOf(item, from) != -1;
75 extend: function(array){
76 for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
81 return (!this.length || ((at < 0) ? at += this.length : at) > this.length) ? null : this[at];
88 getRandom: function(){
89 return (this.length) ? this[$random(0, this.length - 1)] : null;
92 include: function(item){
93 if (!this.contains(item)) this.push(item);
97 combine: function(array){
98 for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
102 erase: function(item){
103 for (var i = this.length; i--; i){
104 if (this[i] === item) this.splice(i, 1);
116 for (var i = 0, l = this.length; i < l; i++){
117 var type = $type(this[i]);
119 array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
124 hexToRgb: function(array){
125 if (this.length != 3) return null;
126 var rgb = this.map(function(value){
127 if (value.length == 1) value += value;
128 return value.toInt(16);
130 return (array) ? rgb : 'rgb(' + rgb + ')';
133 rgbToHex: function(array){
134 if (this.length < 3) return null;
135 if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
137 for (var i = 0; i < 3; i++){
138 var bit = (this[i] - 0).toString(16);
139 hex.push((bit.length == 1) ? '0' + bit : bit);
141 return (array) ? hex : '#' + hex.join('');