列表

详情


JS9. 新数组

描述

请补全JavaScript代码,该函数接受两个参数分别为数组、索引值,要求在不改变原数组的情况下返回删除了索引项的新数组。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1687ms, 内存消耗: 77808KB, 提交时间: 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 _delete = (array,index) => {\n                // 补全代码\n                return array.filter((item,idx)=> index != idx)\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"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 _delete = (array,index) => {\n                // slice(start, end);包含start,不包含end\n                // 返回的是删除元素,而不是被删除之后的元素\n                // return array.slice(index, index + 1);\n                // 正解\n                return array.filter((itme,i) => i !== index);\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"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 _delete = (array,index) => {\n                // 补全代码\n                var newArr=JSON.parse(JSON.stringify(array))\n                newArr.splice(index,1)\n                return newArr;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77776KB, 提交时间: 2022-01-27

{"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 _delete = (array,index) => {\n                // 补全代码\n                let deleteArr = [];\n                for (var i = 0; i < array.length; i++) {\n                    if (i !== index) {\n                        deleteArr.push(array[i])\n                    }\n                }\n                return deleteArr;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77832KB, 提交时间: 2021-12-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 _delete = (array,index) => {\n                // 补全代码\n                const arr = JSON.parse(JSON.stringify(array))\n                arr.splice(index, 1)\n                return arr\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题