求在javascript中生成十个一到五十之间的随机数字,且随机数字不重复,且随机数要冒泡

2024-11-22 07:33:51
推荐回答(2个)
回答(1):

回答(2):

var L = {
orial: [],
result: [],
rand: function(){
for (var i = 0; i < 10; i++) {
L.result.push(Math.floor(1 + Math.random() * 50));
}
L.orial = L.result.slice (0);
},
sorter: function(){
L.result.sort(function(first, second){
if (first > second) {
return -1;
} else if (first < second) {
return 1;
} else {
return 0;
}
});
}
};

L.rand();
console.log(L.orial);
L.sorter();
console.info(L.result);