Home >Web Front-end >JS Tutorial >Js get the maximum and minimum value of an array sample code_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 17:18:281182browse

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
Statement:
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