项目中要用到这种数组
[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]
可以通过一下方法自动生成
const arr = [];
const arr2 = [1, 2, 3, 4, 5];
let len = arr2.length;
const N = 29
let flag = true
let sub = 0
for(let i=0; i < N; i++) {
if(flag) {
sub = sub > 0 ? sub : i > len ? 1 : 0
arr.push(arr2[sub++])
if(sub === len) {
flag = false
sub = len - 2
}
} else {
arr.push(arr2[sub--])
if(sub === -1) {
flag = true
}
}
}
console.log(arr);
let a = [],k = 0,ad = 1;
for(let i=1;i<=4;){
if(k<10){
if(ad === 1 ){
a.push(i++)
if(i === 4){
ad = 0
}
k++
}else{
a.push(i--)
if(i === 1){
ad = 1
}
k++
}
}else{ break}
}
```
网友评论