翻转数组
const arrayReverseChangeMetaArray = (arr = [1,2,3]) => { const res = [] while(arr.length){ res.push(arr.pop()) } return res } const arrayReverse = (arr = [1,2,3]) => { let i = 0, j = arr.length - 1 while(i < j){ [arr[i], arr[j]] = [arr[j], arr[i]] i++ j-- } return arr } Array.prototype.myReserve = function () { let startIdx = 0, endIdx = this.length - 1 while (startIdx < endIdx) { [this[startIdx], this[endIdx]] = [this[endIdx], this[startIdx]] startIdx++ endIdx-- } return this }
以自己现在的努力程度,还没有资格和别人拼天赋