Skip to content
Browse files

Faster(1.5 - 34 times) Array.unique speed.

  • Loading branch information...
1 parent b6131e6 commit 080561e052b492235fe82461187dda97f8e08448 @cainrus committed Dec 20, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 Source/Types/Array.Extras.js
View
9 Source/Types/Array.Extras.js
@@ -47,7 +47,14 @@ Array.implement({
},
unique: function(){
- return [].combine(this);
+ var h = {}, ret = [], arrLen = this.length, next=0, el;
+ while (arrLen--) {
+ el = this[arrLen];
+ if (h[el]) continue;
+ ret[next++] = el;
+ h[el] = 1;
+ }
+ return ret;
},
shuffle: function(){

0 comments on commit 080561e

Please sign in to comment.
Something went wrong with that request. Please try again.