Skip to content

Instantly share code, notes, and snippets.

@keithbloom
Created October 30, 2011 14:33
Show Gist options
  • Select an option

  • Save keithbloom/1325964 to your computer and use it in GitHub Desktop.

Select an option

Save keithbloom/1325964 to your computer and use it in GitHub Desktop.
ExtendingTheJavaScriptArray
var domainNameParts = “www.keithbloom.co.uk”.split(‘.’); // returns [‘www’,’keithbloom’,’co’,’uk’]
var subDomains = [‘www’,’landingpages’,’uk’];
var subtract = function(input, mask) {
for (i = 0; i < input.length - 1; i++) {
for(j = 0; j <= mask.length; j++) {
if(input[i] == mask[j])
input.splice(i,1);
}
}
return input;
};
var result = subtract(domainNameParts, subDomains);
var cookieDomain = '.' + subtract(domainNameParts, subDomains).join('.');
Array.prototype.subtract = function(mask) {
for (i = 0; i < this.length - 1; i++) {
for (j = 0; j <= mask.length; j++) {
if (this[i] === mask[j]) {
this.splice(i, 1);
}
}
}
return this;
};
var cookieDomain = '.' + 'www.keithbloom.co.uk'.split('.').subtract(subDomains).join('.');
Array.porototype.a_namespace_subtract = function() …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment