Fast Algorithm To Find Unique Items in JavaScript Array

Fast Algorithm To Find Unique Items in JavaScript Array.

Array.prototype.unique = function() {    var o = {}, i, l = this.length, r = [];    for(i=0; i<l;i+=1) o[this[i]] = this[i];    for(i in o) r.push(o[i]);    return r;};
Array.prototype.unique = function() {    var a = [], l = this.length;    for(var i=0; i<l; i++) {        for(var j=i+1; j<l; j++)            if (this[i] === this[j]) j = ++i;        a.push(this[i]);    }    return a;};

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s