I'm working on a challenge where I have to find the smallest value in an array and be able to count it if the number occurs more than once. I think I have the format down, but it gives me one more count than there are numbers(4 instead of 3). Can anyone give me some tips? Appreciate any help!
function small(array) {
var smallest = array[0];
var count = 0;
for(var i = 0; i < array.length; i++) {
if(array[i] < smallest) {
smallest = array[i];
}
if(smallest===array[i]) {
count++;
}
}
return count;
}
small([5,6,2,2,2]);