列表

详情


FED2. 数组去重

描述

请补全JavaScript代码,要求去除数组参数中的重复数字项并返回该数组。
注意:
1. 数组元素仅包含数字

示例1

输入:

_deleteRepeat([-1,1,2,2])

输出:

[-1,1,2]

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1683ms, 内存消耗: 77816KB, 提交时间: 2022-02-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _deleteRepeat = array => {\n                // 补全代码\n               let newArr = []\n               array.forEach(item => {\n                   if(newArr.indexOf(item) === -1) {\n                       newArr.push(item)\n                   }\n               });\n                return newArr\n            }    \n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1684ms, 内存消耗: 77812KB, 提交时间: 2022-02-10

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _deleteRepeat = arr => {\n                // 补全代码\n                const array = [];\n    arr.forEach(element => {\n        if(!array.includes(element)){\n            array.push(element);\n        }\n    });\n    return array;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1698ms, 内存消耗: 77820KB, 提交时间: 2022-02-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _deleteRepeat = array => {\n                // 补全代码\n                let newArr = []\n                array.forEach(item=>{\n                    if(newArr.indexOf(item) == -1){\n                        newArr.push(item)\n                    }\n                })\n                return newArr\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1735ms, 内存消耗: 77832KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _deleteRepeat = array => {\n                // 补全代码\n                let newArr = []\n                array.map(item => {\n                    if(newArr.indexOf(item) === -1) {\n                        newArr.push(item)\n                    }\n                })\n                return newArr\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1736ms, 内存消耗: 77772KB, 提交时间: 2021-12-19

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _deleteRepeat = array => {\n                // 补全代码\n                var a = []\n                array.forEach(item=>{\n                    if(a.indexOf(item) == '-1'){\n                        a.push(item)\n                    }\n                })\n                return a\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题