title: Find the number in an array that is closest to a given number
body: <p>I have an Array of integers in javascript, <code>[5,10,15,20,25,30,35]</code>
  when given a number x, how can I find the element in the array that is closest to that number? </p>
  
  <p>If the number is over a value, but less than halfway to the next number, I would choose the smaller value, if it were over halfway to the next number, I would choose the higher number.  </p>
  
  <p>For example 7 would return 5, but 8 would return 10. How can I accomplish this? Any help or tips would be appreciated. I have searched and cannot find a solution. I'm sure this is sort of common.</p>