题解 | #数组去重#
数组去重
http://www.nowcoder.com/practice/0b5ae9c4a8c546f79e2547c0179bfdc2
思路:set内容唯一,将数组去重形成set对象,再对set对象结构并push到新数组中返回
Array.prototype.uniq=function(){ var arr=this var newobj=new Set(arr) var newarr=[] newarr.push(...newobj) return newarr } var s=[false, true, undefined, null, NaN, 0, 1, {}, {}, 'a', 'a', NaN] var res= s.uniq() console.log(res);