title: Javascript find closest number in array without going over
body: <p>How can I modify this very nice function to find the closest number but never higher than the input?</p>
  
  <pre><code>function closest(arr, closestTo){
  
  var closest = Math.max.apply(null, arr);
  
  for(var i = 0; i &lt; arr.length; i++){
      if(arr[i] &gt;= closestTo &amp;&amp; arr[i] &lt; closest) closest = arr[i];
  }
  
  return closest;
  }
  
  console.log(closest(myArray, 1234));
  </code></pre>
  
  <p>Any help appreciated</p>