JavaScript finds the smallest/largest number in an array

Source: Internet
Author: User

The principle of implementation: the sequential lookups of arrays are very similar, and they are all data-specific pairs.

Don't say much nonsense ~

The code is as follows:

/** Parameter Description: * Array: Incoming array, for example: var arr = [5,7,66,78,99,103,126,203,1]; */    functionfindmin (array) {var_min = array[0];//Suppose the smallest number is array[0]        var_indexmin = 0;//assuming the lowest number of subscripts is 0.         for(vari=0;i<array.length;i++){            if(Array[i] < _min) {//if the other elements are greater than the values we assume, it proves that the values we assume are not the smallest_min = Array[i];//Reset The value of the _min_indexmin =i; }                    }         return"The smallest number is:" + _min + "; Subscript:" +_indexmin;            }; //Call:    vararr = [5,7,66,78,99,103,126,203,1]; document.write (Findmin (arr));

can also be corrected, find the largest number of arrays, I will not write, the principle of the same as this ~ ~

Can not understand the place at any time to give me a message ~

The great God, please ignore ~ ^_^

JavaScript finds the smallest/largest number in an array

Related Article

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.