Skip to content

Instantly share code, notes, and snippets.

@agungsijawir
Last active December 18, 2015 07:09
Show Gist options
  • Save agungsijawir/5744904 to your computer and use it in GitHub Desktop.
Save agungsijawir/5744904 to your computer and use it in GitHub Desktop.
Simple way to get minimum and maximum on javascript
<script language="JavaScript">
var larik = [4,3,2,9,44,13,77,84,22,19];
var max = larik[0]; var min = larik[0];
var ukuran = larik.length;
for (var i = 0; i < ukuran; i++) {
if (larik[i] > max) max = larik[i];
else if (larik[i] < min) min = larik[i];
}
/** you can use: alert('Max: ' + max + '\nMin: ' + min); **/
console.log("Max : " + max);
console.log("Min : " + min);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment