列表

详情


FED37. 数组反转

描述

请补全JavaScript函数,要求将参数数组反转之后返回。

原站题解

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

{"css":"","js":"function _reverse(array) {\n    // 补全代码\n    let arr = [];\n    for(let x = array.length - 1;x >= 0;x--){\n        arr.push(array[x]);\n    }\n    return arr\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1734ms, 内存消耗: 77820KB, 提交时间: 2021-11-21

{"css":"","js":"function _reverse(array) {\n    // 补全代码\n    return array.reverse(array);\n    \n}","html":"","libs":[]}

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

{"css":"","js":"function _reverse(array) {\n    // 补全代码\n    let newArray = [];\n    array.forEach((item,index)=> {\n        newArray.push(array[array.length -1 - index]);\n    })\n    return newArray;\n}","html":"","libs":[]}

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

{"css":"","js":"function _reverse(array) {\n    // 补全代码\n    return array.reverse(array)\n    \n}","html":"","libs":[]}

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

{"css":"","js":"function _reverse(array) {\n    // 补全代码\n    array = array.reverse();\n    return array;\n}","html":"","libs":[]}

上一题