This file contains 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
//lo sauer, 2011; lsauer.com | |
/** | |
* I saw this thread: http://stackoverflow.com/questions/840781/easiest-way-to-find-duplicate-values-in-a-javascript-array | |
* The solutions above lacked the elegance that can be done a with map-reduce-like operations | |
* Since this implementation works with native functions, the speed is in most circumstances faster | |
* than any solution using scripted-logic | |
* Additionally, I needed to quickly filter duplicate url-entries for: http://lsauer.github.com/chrome-session-restore/ | |
*/ | |
//copy and paste: without error handling | |
Array.prototype.unique = function(){return this.sort().filter( function(v,i,o){if(i>=0 && v!==o[i-1]) return v;});} |