Edited
ES6 solution:
[...new Set(a)];
Alternative:
Array.from(new Set(a));
Old response. O(n^2) (do not use it with large arrays!)
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…