Skip to content
Browse files

new unique support null

  • Loading branch information...
1 parent 4c77fce commit 0804c13c09e70de870bdc73e6892cce1dba1aa96 @cainrus committed
Showing with 4 additions and 3 deletions.
  1. +4 −3 Source/Types/Array.Extras.js
View
7 Source/Types/Array.Extras.js
@@ -47,15 +47,16 @@ Array.implement({
},
unique: function(){
- var h = {}, ret = [], arrLen = this.length, next=0, el, type;
+ 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 (type !== 'object' && type !== 'function' && h[el]) continue;
+ if((needToCheckTypes[typeof el] || el === null) && h[el]) continue;
ret[next++] = el;
h[el] = 1;
}
- return ret;
+ return ret;
},
shuffle: function(){

0 comments on commit 0804c13

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