How JavaScript gets the maximum and minimum values in an array

Source: Internet
Author: User

How JavaScript gets the maximum and minimum values in the array:
Compared to the size of the values in the array of common operations, compared to the size of a variety of methods, such as the use of the self-contained sort () function, the following to introduce the other more commonly used methods, the code is as follows:

functionGetmaximin (arr,maximin) {if(maximin== "Max")   {     returnMath.max.apply (Math,arr); }  Else if(maximin== "Min")   {     returnMath.min.apply (Math, arr); } } vara=[3,2,4,2,10]; varb=[12,4,45,786,9,78]; Console.log (Getmaximin (A,"Max"));//TenConsole.log (Getmaximin (b, "Min"));//Geneva

The above code can be implemented to remove the maximum and minimum values from the array.
Related reading:
The 1.math.max () function can be found in the Math.max () method section of JavaScript .
The 2.math.min () function can be foundin the section of the Math.min () method of Javascript.
The 3.apply () function can refer to the function and Difference section of the JavaScript call () and apply () .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8819

For more information, refer to: http://www.softwhy.com/javascript/

How JavaScript gets the maximum and minimum values 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.