Created
October 30, 2011 14:33
-
-
Save keithbloom/1325964 to your computer and use it in GitHub Desktop.
ExtendingTheJavaScriptArray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var domainNameParts = “www.keithbloom.co.uk”.split(‘.’); // returns [‘www’,’keithbloom’,’co’,’uk’] | |
| var subDomains = [‘www’,’landingpages’,’uk’]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cookieDomain = '.' + subtract(domainNameParts, subDomains).join('.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cookieDomain = '.' + 'www.keithbloom.co.uk'.split('.').subtract(subDomains).join('.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.porototype.a_namespace_subtract = function() … |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment