Skip to content

Instantly share code, notes, and snippets.

View zykadelic's full-sized avatar

Andreas Fransson zykadelic

View GitHub Profile
// Douglas Crockford's Supplant
if(!String.prototype.supplant){
String.prototype.supplant = function(o){
return this.replace(/\{([^{}]*)\}/g, function(a, b){
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
});
};
}
@zykadelic
zykadelic / array.remove.js
Created March 25, 2014 17:32
Returns a new array without any occurrence of the argument.
Array.prototype.remove = function(obj){
// Copy the array, so we don't override it
var array = this.slice(0);
for(var i = 0; i < array.length; i++){
// Use while-loop to find adjacent equal objects
while(array[i] === obj){
// Remove this[i]
array.splice(i, 1)[0];