Last modified on 25 April 2009, at 03:49

Algorithms/Find maximum/jscript

 <script type="text/jscript">   
  function findMax(intA) {
     if ( intA.length == 0 ) 
        return 0;
    if ( intA.length == 1 ) 
        return 1;
     var o_intMax = intA[0];
     for (var p_intI = 1; p_intI < intA.length; p_intI++) {
         if ( intA[p_intI] > o_intMax ) {
            o_intMax = intA[p_intI];
         } // end if
     } // end loop
     return o_intMax;
   } // end method
   var intA = new  Array(1,9,6);
   document.write(findMax(intA));
 </script>