画骨成沙 2022-05-04 13:54:54
function sortPuke(arr) {
let keyList = [];//arr对应的key
let alenList = [];
let result = [];//最终结果
let spot = true;
if (arr.length === 1) {
return arr
}
if (arr.length > 1) {
for (let index = 0; index < arr.length; index++) {
alenList.push(index)
}
while (alenList.length) {
if (alenList.length === 1) {
keyList.push(alenList.shift())
}
if (spot && alenList.length > 1) {
keyList.push(alenList.shift())
}
if (!spot && alenList.length > 1) {
alenList.push(alenList.shift())
}
spot = !spot
}
}
for (let j = 0; j < arr.length; j++) {
result[keyList[j]] = arr[j]
}
return result;
}
console.log(sortPuke([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]));
//[ 1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7 ]
- 共 1 页
- 1
不是应该String('11').toString() == new String('11')吗
第 106 题:分别写出如下代码的返回值