列表

详情


FED25. 数组去重

描述

为 Array 对象添加一个去除重复项的方法

示例1

输入:

[false, true, undefined, null, NaN, 0, 1, {}, {}, 'a', 'a', NaN]

输出:

[false, true, undefined, null, NaN, 0, 1, {}, {}, 'a']

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 868ms, 内存消耗: 77980KB, 提交时间: 2020-11-23

{"css":"","js":"Array.prototype.uniq = function () {\n    return Array.from(new Set(this));\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 869ms, 内存消耗: 77860KB, 提交时间: 2020-11-23

{"css":"","js":"Array.prototype.uniq = function () {\n    return [...(new Set(this))];\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 869ms, 内存消耗: 77900KB, 提交时间: 2020-12-21

{"css":"","js":"Array.prototype.uniq = function () {\n    return [...(new Set(this))];\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 870ms, 内存消耗: 77880KB, 提交时间: 2021-01-17

{"css":"","js":"Array.prototype.uniq = function () {\n    //从后往前找重复项,避免数组移动元素过多\n    \n    return [...(new Set(this))]\n     \n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 871ms, 内存消耗: 77840KB, 提交时间: 2020-11-18

{"css":"","js":"Array.prototype.uniq = function () {\n    var result = [];\n    var flag = true;\n    for(let i=0;i<this.length;i++){\n        if(result.indexOf(this[i]) == -1){\n            if(this[i] !== this[i]){\n                if(flag){\n                    result.push(this[i]);\n                    flag = false;\n                }\n            }\n            else{\n                result.push(this[i]);\n            }           \n        }\n    }\n    return result;\n}","html":"","libs":[]}

上一题