标签:
var randomNumber = function (min, max, length, arr) {
var num = parseInt(Math.random() * max);
if (num < min) {
randomNumber(min, max, length, arr);
return;
}
if (arr.length >= length) {
return arr;
}
arr.push(num);
randomNumber(min, max, length, arr);
}
window.onload = function () {
var arr = [];
randomNumber(10, 21, 5, arr);
arr.sort(function (a, b) {
return b - a;
});
console.log(arr);
}
JavaScript 选取 min 到 max 之间的 length 个数字并排序
标签:
原文地址:http://www.cnblogs.com/xiaochechang/p/5850616.html