Skip to content

Instantly share code, notes, and snippets.

@danielkhan
Last active December 3, 2016 18:45
Show Gist options
  • Select an option

  • Save danielkhan/0112ba41ee8b5195ac17014ed0e0969f to your computer and use it in GitHub Desktop.

Select an option

Save danielkhan/0112ba41ee8b5195ac17014ed0e0969f to your computer and use it in GitHub Desktop.
var numbers = [12, 22, 45, 13, 66, 1, 100, 1, 210, 10, 11];
var max = 0;
for (var i = 0;i < numbers.length; i++){
console.log(`numbers.length is ${numbers.length}, i is ${i}, numbers at position ${i} is ${numbers[i]}`);
console.log(`Now we test if ${max} is lower than ${numbers[i]}`);
if(max < numbers[i]){
console.log(`I is lower, so now ${numbers[i]} is the new max.`);
max = numbers[i];
console.log(`Max is now ${max}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment