Created
January 10, 2021 22:43
-
-
Save ross-u/4aaafa36d40bd871f8b6ebad3e2a4c8b to your computer and use it in GitHub Desktop.
JS Infinity use case example
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
function findSmallest(array) { | |
var min = Infinity; // <== control variable used to check agains and store the value | |
for (var i = 0; i < array.length; i++) { | |
var currentNum = array[i]; | |
if (currentNum < min) { | |
min = currentNum; | |
} | |
} | |
return min; | |
} | |
findSmallest( [67, -7, 231, -55, 0] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment