Returns the maximum and minimum values of an array.

Source: Internet
Author: User
Array. Prototype. max = function () {// maximum value
Return math. Max. Apply ({}, this)
}

Array. Prototype. min = function () {// minimum value
Return math. Min. Apply ({}, this)
}

VaR mymax = [1, 2, 3]. Max () // => 3
VaR mymin = [1, 2, 3]. Min () // => 1

Console. Log (mymin, mymax); VaR _ getmin = function (ARR) {// minimum value
Return math. Min. Apply (Math, arr );
}
VaR _ getmax = function (ARR) {// maximum value
Return math. Max. Apply (Math, arr );
}

VaR temparr = [1, 2, 4];
VaR mymin = _ getmin (temparr); // => 1
VaR mymax = _ getmax (temparr); // => 4
Console. Log (mymin, mymax); // 1, 4

Returns the maximum and minimum values of an array.

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.