Array Max

<title>Array Max</title>
<script type="text/javascript">
// From:

var v=[10,8,42,50] // So looking to find 50
function srchMaxV() {
var maxV = 0; // or value smaller that smallest in array to search, like = -1000;
for (i=0; i if (v[i] > maxV) { maxV = v[i]; }
return maxV;

function NumSort(a,b) { return a-b; } // required for sorting numbers only
function sortMaxV() {
var sortedV = new Array();
sortedV = v.sort(NumSort);
alert('Max: '+sortedV[sortedV.length-1]+'\nMin: '+sortedV[0]);
<button onclick="alert('Max: '+srchMaxV())">Search for Max
<button onclick="sortMaxV()">Sort for Max/Min


Popular posts from this blog

Set limit wp_nav_menu

Conut document have children that are show in navigation