题解 | #数组去重#
数组去重
http://www.nowcoder.com/practice/0b5ae9c4a8c546f79e2547c0179bfdc2
// set方法 Array.prototype.uniq = function () { return [...new Set(this)] }
// map Array.prototype.uniq = function () { const sMap = new Map() this.forEach((itm,idx) => { if(!sMap.has(itm)){ sMap.set(itm,'1') } }) return Array.from(sMap.keys()) }