Choose 10 numbers between 10-100, deposit an array, and sort

Source: Internet
Author: User

Choose 10 numbers between 10-100, deposit an array, and sort
Implement the Function function
function Randomnub (Arr,len,min,max) {
If the given length is greater than the value range, the hint is exceeded
if (len>= (max-min)) {
Return "exceeds" +min+ "-" +max+ "between the number of ranges" + (max-min-1) + "total number of";
}
Sort from small to large, implementing the array in descending order
if (Arr.length>=len) {
Arr.sort (function (b) {
return a-B;
});
return arr;
}
Define the current number
var nownub=parseint (Math.random () * (max-min-1)) + (min+1);
When producing a random number = = of a number in an array,
for (Var j=0;j<arr.length;j++) {
if (Nownub==arr[j]) {
RANDOMNUB (Arr,len,min,max);
Return
}
}
Arr.push (NOWNUB);
RANDOMNUB (Arr,len,min,max);
return arr;
}
var arr=[];
Call this function to implement the function
Console.log (RANDOMNUB (arr,20,10,100))

Choose 10 numbers between 10-100, save in an array, and sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.