I need Obtain the nearest smallest number of an array, not the closest number
var counts = [4, 9, 15, 6, 2],
goal = 13;
var closest = counts.reduce(function(prev, curr) {
return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev);
});
console.log(closest);
Above, the result is 15
but it should be 9
as I want the lowest number closest to the goal number.