Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


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

wants to merge 3 commits into from

2 participants


You're storing the values in an object, with the values as keys. Doing that will call valueOf() of each value. When the values are strings or numbers it's ok, however with other objects this probably won't work.

Also could you provide some


Updated. Tests:
Please check it. Do we need sugar or speed in core code? Need a framework for micro optimizations?


Very nice, however the cases I tried to explain, still don't work, see with your code and with the current code.

Faster is better, but what's more important is readability and API. Especially with these JS functions, which are usually not the bottleneck in your application (compared to DOM stuff).



@cainrus cainrus closed this

Thanks for your effort though, much appreciated! If you see other possible improvements, please let us know :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 Source/Types/Array.Extras.js
11 Source/Types/Array.Extras.js
@@ -47,7 +47,16 @@ Array.implement({
unique: function(){
- return [].combine(this);
+ var h = {}, ret = [], arrLen = this.length, next=0, el, type,
+ needToCheckTypes = {'undefined': 1, 'boolean': 1, 'number': 1, 'string': 1};
+ while (arrLen--) {
+ el = this[arrLen];
+ type = typeof el;
+ if((needToCheckTypes[typeof el] || el === null) && h[el]) continue;
+ ret[next++] = el;
+ h[el] = 1;
+ }
+ return ret;
shuffle: function(){
Something went wrong with that request. Please try again.