Home > Web Front-end > JS Tutorial > body text

Js get the maximum and minimum value of an array sample code_javascript skills

WBOY
Release: 2016-05-16 17:18:28
Original
1143 people have browsed it

When working on a project, I encountered a problem of only taking the maximum and minimum values ​​in the returned query content.

Firstly

Copy the code The code is as follows:

/**
* Maximum value of array
* @param {Object} array
* @return {TypeName}
*/
Array.max=function(array)
{
return Math.max.apply(Math,array);
}

/**
* Array minimum value
* @param {Object} array
* @return {TypeName}
* /
Array.min=function(array)
{
return Math.min.apply(Math,array);
}

Call
Copy code The code is as follows:

//Processing vertical coordinate adaptation--start
var yData = data .rows[i];
var yMin = Array.min(yData);//Minimum value of ordinate
var yMax = Array.max(yData);//Maximum value of ordinate
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!