复杂随机函数
作者:互联网
async getHome() {
let temp = await http.getHome();
//随机方法
function getRandomElements(arr, count) {
var shuffled = arr.slice(0),
i = arr.length,
min = i - count,
temp,
index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
// console.log(shuffled[i]);
}
return shuffled.slice(min);
}
if (temp != null) { this.recommend.push(getRandomElements(temp, 1)); } // console.log(this.recommend); },
if (temp != null) { this.recommend.push(getRandomElements(temp, 1)); } // console.log(this.recommend); },
标签:index,arr,shuffled,temp,复杂,min,随机,recommend,函数 来源: https://www.cnblogs.com/zjxzhj/p/14765463.html