题解 | #数组去重#

数组去重

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

        Array.prototype.uniq = function () {
            // 1.使用集合快速去重
            <!-- return Array.from(new Set(this)) -->
            // 2.使用数组的includes函数进行判断去重
            let set = []
            this.forEach(item => {
                if(!set.includes(item)) {
                    set.push(item)
                }
            })
            return set
        }

全部评论

相关推荐

累死的一条狗:***一人顶10人那你给我发10个人的工资总和吗
点赞 评论 收藏
分享
想run的马里奥在学...:这个学历帮你扫平百分之80的障碍,投就完了,这会找不到就等3月暑期一样能找到
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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