题解 | #数组去重#

数组去重

http://www.nowcoder.com/practice/0b5ae9c4a8c546f79e2547c0179bfdc2

这道题有个坑,就是 NaNNaN 是不相等的,所以用 == 或者 === 无法进行判断,可以使用的是

  • Object.is
  • includes
Array.prototype.uniq = function () {
     let result = this.reduce((pre,curr)=>{
         if(!pre.includes(curr)){
             pre.push(curr);
         }
         return pre;
     },[])
     
     return result;
}
全部评论

相关推荐

陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
昨天 16:00
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务