Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ran a "for ... in " on Array, VM8, Chrome 31.x
function (start,length){start=start||0;if(start<0)start=this.length+start;length=length||(this.length-start);var newArray=[];for(var i=0;i<length;i++)newArray[i]=this[start++];return newArray} VM2066:4
function (item){var i=0;var len=this.length;while(i<len){if(this[i]===item){this.splice(i,1);len--}else{i++}}return this} VM2066:4
function (item,from){return this.indexOf(item,from)!=-1} VM2066:4
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} VM2066:4
function (array){for(var i=0,j=array.length;i<j;i++)this.push(array[i]);return this} VM2066:4
function (array){for(var i=0,l=array.length;i<l;i++)this.include(array[i]);return this} VM2066:4
function include(object) {
if (Object.isFunction(this.indexOf))
if (this.indexOf(object) != -1) return true;
var found = false;
this.each(function(value) {
if (value == object) {
found = true;
throw $break;
}
});
return found;
} VM2066:4
function (){return this[$random(0,this.length-1)]||null} VM2066:4
function (){return this[this.length-1]||null} VM2066:4
function each(iterator, context) {
try {
this._each(iterator, context);
} catch (e) {
if (e != $break) throw e;
}
return this;
} VM2066:4
function (item,from){return this.indexOf(item,from)!=-1} VM2066:4
function (array){if(this.length<3)return false;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('')} VM2066:4
function (array){if(this.length!=3)return false;var rgb=[];for(var i=0;i<3;i++){rgb.push(parseInt((this[i].length==1)?this[i]+this[i]:this[i],16))}return array?rgb:'rgb('+rgb.join(',')+')'} VM2066:4
function (){var red=this[0],green=this[1],blue=this[2];var hue,saturation,brightness;var max=Math.max(red,green,blue),min=Math.min(red,green,blue);var delta=max-min;brightness=max/255;saturation=(max!=0)?delta/max:0;if(saturation==0){hue=0}else{var rr=(max-red)/delta;var gr=(max-green)/delta;var br=(max-blue)/delta;if(red==max)hue=br-gr;else if(green==max)hue=2+rr-br;else hue=4+gr-rr;hue/=6;if(hue<0)hue++}return[Math.round(hue*360),Math.round(saturation*100),Math.round(brightness*100)]} VM2066:4
function (){var br=Math.round(this[2]/100*255);if(this[1]==0){return[br,br,br]}else{var hue=this[0]%360;var f=hue%60;var p=Math.round((this[2]*(100-this[1]))/10000*255);var q=Math.round((this[2]*(6000-this[1]*f))/600000*255);var t=Math.round((this[2]*(6000-this[1]*(60-f)))/600000*255);switch(Math.floor(hue/60)){case 0:return[br,t,p];case 1:return[q,br,p];case 2:return[p,br,t];case 3:return[p,q,br];case 4:return[t,p,br];case 5:return[br,p,q]}}return false} VM2066:4
function eachSlice(number, iterator, context) {
var index = -number, slices = [], array = this.toArray();
if (number < 1) return array;
while ((index += number) < array.length)
slices.push(array.slice(index, index+number));
return slices.collect(iterator, context);
} VM2066:4
function () {
if (arguments.length === 0) {
return method.call(this, Prototype.K);
} else if (arguments[0] === undefined) {
var args = slice.call(arguments, 1);
args.unshift(Prototype.K);
return method.apply(this, args);
} else {
return method.apply(this, arguments);
}
} VM2066:4
function () {
if (arguments.length === 0) {
return method.call(this, Prototype.K);
} else if (arguments[0] === undefined) {
var args = slice.call(arguments, 1);
args.unshift(Prototype.K);
return method.apply(this, args);
} else {
return method.apply(this, arguments);
}
} VM2066:4
function () {
if (arguments.length === 0) {
return method.call(this, Prototype.K);
} else if (arguments[0] === undefined) {
var args = slice.call(arguments, 1);
args.unshift(Prototype.K);
return method.apply(this, args);
} else {
return method.apply(this, arguments);
}
} VM2066:4
function detect(iterator, context) {
var result;
this.each(function(value, index) {
if (iterator.call(context, value, index, this)) {
result = value;
throw $break;
}
}, this);
return result;
} VM2066:4
function filter() { [native code] } VM2066:4
function filter() { [native code] } VM2066:4
function grep(filter, iterator, context) {
iterator = iterator || Prototype.K;
var results = [];
if (Object.isString(filter))
filter = new RegExp(RegExp.escape(filter));
this.each(function(value, index) {
if (filter.match(value))
results.push(iterator.call(context, value, index, this));
}, this);
return results;
} VM2066:4
function include(object) {
if (Object.isFunction(this.indexOf))
if (this.indexOf(object) != -1) return true;
var found = false;
this.each(function(value) {
if (value == object) {
found = true;
throw $break;
}
});
return found;
} VM2066:4
function inGroupsOf(number, fillWith) {
fillWith = Object.isUndefined(fillWith) ? null : fillWith;
return this.eachSlice(number, function(slice) {
while(slice.length < number) slice.push(fillWith);
return slice;
});
} VM2066:4
function inject(memo, iterator) {
iterator = iterator || Prototype.K;
var context = arguments[2];
return _reduce.call(this, iterator.bind(context), memo);
} VM2066:4
function invoke(method) {
var args = $A(arguments).slice(1);
return this.map(function(value) {
return value[method].apply(value, args);
});
} VM2066:4
function max(iterator, context) {
iterator = iterator || Prototype.K;
var result;
this.each(function(value, index) {
value = iterator.call(context, value, index, this);
if (result == null || value >= result)
result = value;
}, this);
return result;
} VM2066:4
function min(iterator, context) {
iterator = iterator || Prototype.K;
var result;
this.each(function(value, index) {
value = iterator.call(context, value, index, this);
if (result == null || value < result)
result = value;
}, this);
return result;
} VM2066:4
function partition(iterator, context) {
iterator = iterator || Prototype.K;
var trues = [], falses = [];
this.each(function(value, index) {
(iterator.call(context, value, index, this) ?
trues : falses).push(value);
}, this);
return [trues, falses];
} VM2066:4
function pluck(property) {
var results = [];
this.each(function(value) {
results.push(value[property]);
});
return results;
} VM2066:4
function reject(iterator, context) {
var results = [];
this.each(function(value, index) {
if (!iterator.call(context, value, index, this))
results.push(value);
}, this);
return results;
} VM2066:4
function sortBy(iterator, context) {
return this.map(function(value, index) {
return {
value: value,
criteria: iterator.call(context, value, index, this)
};
}, this).sort(function(left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
}).pluck('value');
} VM2066:4
function clone() {
return slice.call(this, 0);
} VM2066:4
function toArray() {
return this.map();
} VM2066:4
function zip() {
var iterator = Prototype.K, args = $A(arguments);
if (Object.isFunction(args.last()))
iterator = args.pop();
var collections = [this].concat(args).map($A);
return this.map(function(value, index) {
return iterator(collections.pluck(index));
});
} VM2066:4
function size() {
return this.length;
} VM2066:4
function inspect() {
return '[' + this.map(Object.inspect).join(', ') + ']';
} VM2066:4
function detect(iterator, context) {
var result;
this.each(function(value, index) {
if (iterator.call(context, value, index, this)) {
result = value;
throw $break;
}
}, this);
return result;
} VM2066:4
function reverse() { [native code] } VM2066:4
function forEach() { [native code] } VM2066:4
function clear() {
this.length = 0;
return this;
} VM2066:4
function first() {
return this[0];
} VM2066:4
function last() {
return this[this.length - 1];
} VM2066:4
function compact() {
return this.select(function(value) {
return value != null;
});
} VM2066:4
function flatten() {
return this.inject([], function(array, value) {
if (Object.isArray(value))
return array.concat(value.flatten());
array.push(value);
return array;
});
} VM2066:4
function without() {
var values = slice.call(arguments, 0);
return this.select(function(value) {
return !values.include(value);
});
} VM2066:4
function uniq(sorted) {
return this.inject([], function(array, value, index) {
if (0 == index || (sorted ? array.last() != value : !array.include(value)))
array.push(value);
return array;
});
} VM2066:4
function intersect(array) {
return this.uniq().findAll(function(item) {
return array.indexOf(item) !== -1;
});
} VM2066:4
function clone() {
return slice.call(this, 0);
} VM2066:4
function () {
for(i = 0; i < this.length; i++){
for(j = this.length-1; j>i; j--){
if(this[i][0] == this[j][0]){
this.splice(j,1);
}
}
}
} VM2066:4
function () {
for(i = 0; i <= this.length; i++){
this.shift();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.