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) ? this.item(-1) : null;
84 getRandom: function(){
85 return (this.length) ? this[$random(0, this.length - 1)] : null;
88 include: function(item){
89 if (!this.contains(item)) this.push(item);
93 combine: function(array){
94 for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
98 erase: function(item){
99 for (var i = this.length; i--; i){
100 if (this[i] === item) this.splice(i, 1);
112 for (var i = 0, l = this.length; i < l; i++){
113 var type = $type(this[i]);
115 array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
120 hexToRgb: function(array){
121 if (this.length != 3) return null;
122 var rgb = this.map(function(value){
123 if (value.length == 1) value += value;
124 return value.toInt(16);
126 return (array) ? rgb : 'rgb(' + rgb + ')';
129 rgbToHex: function(array){
130 if (this.length < 3) return null;
131 if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
133 for (var i = 0; i < 3; i++){
134 var bit = (this[i] - 0).toString(16);
135 hex.push((bit.length == 1) ? '0' + bit : bit);
137 return (array) ? hex : '#' + hex.join('');