Created
October 25, 2019 19:49
-
-
Save marksherman/8030a554d9b5ae38de7f4825f6daaa1b to your computer and use it in GitHub Desktop.
Finding the Largest value in an Array (javascript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readings = [0, 5, 9, 18, 2, 9, 5]; | |
// find the largest value in the array 'readings' | |
var max = 0; | |
for (var i = 0; i < readings.length; i++) { | |
if (readings[i] > max) { | |
max = readings[i]; | |
} | |
} | |
console.log('The highest reading is: ' + max); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can copy this whole thing into the javascript console and it will work! Try it out!