如何在Javascript中进行Butterfly Shuffle?

时间:2018-04-17 09:30:00

标签: javascript shuffle

如何在java脚本中为butterfly shuffle创建数字。

Input = 0,1,2,3,4,5,6,7,8,9;

Result = 9,7,5,3,1,0,2,4,6,8;

1 个答案:

答案 0 :(得分:0)

试试这段代码



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());
&#13;
&#13;
&#13;