Javascript reduce duplicated element

1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Array.prototype.unique = function(){
var result = []; // creat a variable to store the result
var hash = {}; // create a hash element
var type = null;
this.forEach(function(e){
type = typeof(e);
hash[e] || (hash[e] = []); // if current element is already in hash, do nothing. Otherwise create an attribute based on current element
if(hash[e].indexOf(type) < 0)
{
result.push(e);
hash[e].push(type);
}
});
return result;
}