Jump to content

Algorithms/Find maximum/jscript 4

From Wikibooks, open books for an open world

<script language="Jscript">

 function findMin(intA) {   
  if ( intA.length == 0 ) 
    return 0;
  if ( intA.length == 1 ) 
    return 1;
   var o_intMin = intA[0];
   for (var p_intI = 1; p_intI < intA.length; p_intI += 1) {
     if ( intA[p_intI] < o_intMin ) {
      o_intMin = intA[p_intI];
     } // end if
   } // end loop
   return o_intMin;   
 } // end method  
 function findMax(intA) {
  for ( var i_intI = 0; i_intI < intA.length;i_intI += 1 )
    intA[i_intI] = intA[i_intI] * -1;
  var o_intMax = findMin(intA);
  o_intMax = o_intMax * -1;
  return o_intMax;
 } // end method
 var cc = new Array(1,2,3,4);
 document.write(findMax(cc)); 
</script>