Finding Things

Variation 1 on the first exercise, JavaScript 2,

by GOLDENSWORD559

HTML

<script src="http://wilderland.org/javascript2/findSmallestTest.js"></script>
<div class='explanation'>
    The tests in this fiddle expect a function called "findSmallest". The tests will pass the function an array of numbers, as in the "findBiggest" exercise.  The function should return the smallest value in the array.
</div>
<button>Click To Run Tests</button>
<div id=results></div>

CSS

.explanation {
    border: 1px solid #010310;
    border-radius: 10px;
    box-shadow: 2px 2px 3px rgba(12,10,30,0.3);
    margin: 10px 0 20px 5px;
    font-family: sans-serif;
    
    padding: 15px;
    width: 30em;
}

JavaScript

function findSmallest(list) {
    var i, smallest = Number.MAX_VALUE, current;
    for (var i = 0; i < list.length; ++i) {
        current = list[i];
        if (current < 0 || current < smallest)
            smallest = current;
    }
    return smallest;
}