如何在java脚本中为蝴蝶洗牌制作数字。
Input = 0,1,2,3,4,5,6,7,8,9;
Result = 9,7,5,3,1,0,2,4,6,8;
试试这段代码
var a = "0,1,2,3,4,5,6,7,8,9";
var arr = a.split(',');
var arrA = [];
var arrB = [];
for (var i = 0; i < arr.length; i += 2) {
arrA.push(arr[i]);
}
for (var i = 1; i < arr.length; i += 2) {
arrB.push(arr[i]);
}
arrA.reverse();
var res = arrA.concat(arrB);
res.reverse();
console.log(res.toString());