6 description: Contains Array Prototypes like each, contains, and erase.
8 license: MIT-style license.
19 invoke: function(methodName){
20 var args = Array.slice(arguments, 1);
21 return this.map(function(item){
22 return item[methodName].apply(item, args);
26 every: function(fn, bind){
27 for (var i = 0, l = this.length; i < l; i++){
28 if ((i in this) && !fn.call(bind, this[i], i, this)) return false;
33 filter: function(fn, bind){
35 for (var i = 0, l = this.length; i < l; i++){
36 if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]);
42 return this.filter(function(item){
47 indexOf: function(item, from){
48 var len = this.length;
49 for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
50 if (this[i] === item) return i;
55 map: function(fn, bind){
57 for (var i = 0, l = this.length; i < l; i++){
58 if (i in this) results[i] = fn.call(bind, this[i], i, this);
63 some: function(fn, bind){
64 for (var i = 0, l = this.length; i < l; i++){
65 if ((i in this) && fn.call(bind, this[i], i, this)) return true;
70 associate: function(keys){
71 var obj = {}, length = Math.min(this.length, keys.length);
72 for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
76 link: function(object){
78 for (var i = 0, l = this.length; i < l; i++){
79 for (var key in object){
80 if (object[key](this[i])){
81 result[key] = this[i];
90 contains: function(item, from){
91 return this.indexOf(item, from) != -1;
94 append: function(array){
95 this.push.apply(this, array);
100 return (this.length) ? this[this.length - 1] : null;
103 getRandom: function(){
104 return (this.length) ? this[Number.random(0, this.length - 1)] : null;
107 include: function(item){
108 if (!this.contains(item)) this.push(item);
112 combine: function(array){
113 for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
117 erase: function(item){
118 for (var i = this.length; i--;){
119 if (this[i] === item) this.splice(i, 1);
131 for (var i = 0, l = this.length; i < l; i++){
132 var type = typeOf(this[i]);
133 if (type == 'null') continue;
134 array = array.concat((type == 'array' || type == 'collection' || type == 'arguments' || instanceOf(this[i], Array)) ? Array.flatten(this[i]) : this[i]);
140 for (var i = 0, l = this.length; i < l; i++){
141 if (this[i] != null) return this[i];
146 hexToRgb: function(array){
147 if (this.length != 3) return null;
148 var rgb = this.map(function(value){
149 if (value.length == 1) value += value;
150 return value.toInt(16);
152 return (array) ? rgb : 'rgb(' + rgb + ')';
155 rgbToHex: function(array){
156 if (this.length < 3) return null;
157 if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
159 for (var i = 0; i < 3; i++){
160 var bit = (this[i] - 0).toString(16);
161 hex.push((bit.length == 1) ? '0' + bit : bit);
163 return (array) ? hex : '#' + hex.join('');
170 Array.alias('extend', 'append');
172 var $pick = function(){
173 return Array.from(arguments).pick();