题解 | #数组去重#

数组去重

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

includes方法可以感知 undefined、null、NaN,对于对象检查的是地址,所以不同对象不会导致includes为true

Array.prototype.uniq = function () {
    let temp = []
    this.forEach(e => {
        if (!temp.includes(e)) temp.push(e)
    })
    return temp
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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