title: Get closest date to current date (javascript)
body: <p>So I have an array of dates and want to get the current date and put it into a countdown clock
  I have this code atm:</p>
  
  <pre><code> &lt;script&gt;
      var dates = [
        '24/5/2017',
        '12/6/2017',
        '14/6/2017',
        '16/6/2017',
        '20/6/2017',
        '20/6/2017',
        '22/6/2017',
        '23/6/2017',
        '26/6/2017'
  
      ];
  
      function sortDates(dates) {
        return dates.map(function(date) {
          return new Date(date).getTime();
        }).sort(function(a, b) {
          return a - b;
        });
      }
  
      var orderedDates = sortDates(dates);
      document.getElementById("demoo").innerHTML = orderedDates
  
      var nextDate = orderedDates.filter(function(date) {
        return (var now = new Date().getTime(); - date) &gt; 0;
      })[0];
      document.getElementById("demo").innerHTML = nextDate
  
      var x = setInterval(function() {
  
          // Get todays date and time
          var now = new Date().getTime();
  
          // Find the distance between now an the count down date
          var distance = nextDate - now;
  
          // Time calculations for days, hours, minutes and seconds
          var days = Math.floor(distance / (1000 * 60 * 60 * 24));
          var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
          var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
          var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  
          // Output the result in an element with id="demo"
          document.getElementById("demo").innerHTML = days + "d " + hours + "h "
          + minutes + "m " + seconds + "s ";
  
          // If the count down is over, write some text 
          if (distance &lt; 0) {
              clearInterval(x);
              document.getElementById("demo").innerHTML = "EXPIRED";
          }
      }, 1000);
      &lt;/script&gt;
      &lt;center&gt;&lt;h2&gt;Core Maths 2&lt;/h2&gt;&lt;center&gt;
  </code></pre>
  
  <p>This doesn't seem to do anything, so I don't really know what to do. at the moment it just comes up with NAN for the countdown</p>