Voici un simple algorithme, et apparemment rapide, trouvé sur http://www.shamasis.net/2009/09/fast-algorithm-to-find-unique-items-in-javascript-array/ et que j’ai raccourci légèrement :
Array.prototype.unique=[].unique||function(){var o={},i,l=this.length,r=[];for(i=0;i<l;i++)o[this[i]]=this[i];for(i in o)r.push(o[i]);return r}
// exemple
var tab=[1, 5, 2, 4, 1, 5, 4, 1, 5, 6, 8 ];
tab.unique(); // [1, 5, 2, 4, 6, 8]
![Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Facebook Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Facebook](http://blog.kodono.info/wordpress/wp-content/plugins/simple-social-bookmarks/images/facebook.png)
![Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Google+ Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Google+](http://blog.kodono.info/wordpress/wp-content/plugins/simple-social-bookmarks/images/googleplus.png)
![Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Twitter Share 'Un algorithme court et rapide pour Array.unique() [Javascript]' on Twitter](http://blog.kodono.info/wordpress/wp-content/plugins/simple-social-bookmarks/images/twitter.png)

Related Articles
No user responded in this post
Leave A Reply