JS算法题
reserve
让数组反转倒置
const arr = [1, 2, 3, 4, 5];
arr.reverse();
console.log(arr); // [5, 4, 3, 2, 1]
面试题一;用js来模拟reserve
const arr = [1, 2, 3, 4, 5];
function reverse(arr) {
let l = 0;
let r = arr.length - 1;
while (l < r) {
let temp = arr[l];
.
原创
2021-05-13 15:31:12 ·
96 阅读 ·
0 评论