我想创建一个整数的勾号旋转。
例如,我有数组中的数字列表:
let array = [
1,2,3,4,5,6,7
]
然后找到一个随机开始。
例如
let random_start = 4
现在刻度结果应该是:
console.log(this.tickoff(array,random_start))
// 4,5,6,7,1,2,3
最佳答案
这工作正常。
function tickOff(array, random)
{
var result = array.splice(random,array.length-random);
return result.concat(array);
}
var array = [1,2,3,4,5,6,7];
var index = Math.floor(Math.random()*array.length), value = array[index];
console.log("Tick off with random index : "+index+" Result : "+tickOff(array, index).join(","));
var array = [1,2,3,4,5,6,7];
var value = Math.floor(Math.random()*array.length)+1, index = array.indexOf(value);
console.log("Tick off with random value : "+value+" Result : "+tickOff(array, index).join(","));
关于javascript - 勾选随机开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515211/