日期:2014-05-16 浏览次数:20338 次
function calc(i, oldArr) {
var i = i
------解决方案--------------------
0,
oldArr = oldArr
------解决方案--------------------
[0,1,2,3,4,5,6,7,8,9,10],
newArr = [],
len = oldArr.length,
half = (oldArr.length - 1) / 2;
for(var j = 0; j < len; j++) {
if(j < half) {
newArr.push((i - (half - j) < 0) ? len + i - (half - j) : (i - (half - j)));
} else if(j > half) {
newArr.push(i + (j - half));
} else {
newArr.push(i)
}
}
console.log(newArr);
return newArr;
}
calc(1);
var arr = [0,1,2,3,4];
var newArr = [];
var i=0;
newArr = arr.slice((3+i)%arr.length).concat(arr).slice(0,arr.length);
alert(newArr);