< Algorithms < Find maximum
<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>
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.