weather-forecast.js
function($, times, N) {
  N = typeof N === 'undefined' ? 24 : N;

  return _.chain(times).map(function(time){
    // map to back to cheerio'fied object so we can read attr()
    return $(time);
  }).filter(function(time){
    // filter by instantaneous forecasts only
    return time.attr("from") == time.attr("to");
  }).sortBy(function(time){
    // sort by closest to most distant time
    var from = new Date(time.attr("from"));
    return Math.abs((new Date()).getTime() - from.getTime());
  }).first(N).value();
}
function($, times, N) {
  N = typeof N === 'undefined' ? 24 : N;

  return _.chain(times).map(function(time){
    // map to back to cheerio'fied object so we can read attr()
    return $(time);
  }).filter(function(time){
    // filter by instantaneous forecasts only
    return time.attr("from") == time.attr("to");
  }).sortBy(function(time){
    // sort by closest to most distant time
    var from = new Date(time.attr("from"));
    return Math.abs((new Date()).getTime() - from.getTime());
  }).first(N).value();
}
function ( $ , times , N ) { N = typeof N === 'undefined' ? 24 : N ; return _ . chain ( times ) . map ( function ( time ) { // map to back to cheerio'fied object so we can read attr() return $ ( time ) ; } ) . filter ( function ( time ) { // filter by instantaneous forecasts only return time . attr ( "from" ) == time . attr ( "to" ) ; } ) . sortBy ( function ( time ) { // sort by closest to most distant time var from = new Date ( time . attr ( "from" ) ) ; return Math . abs ( ( new Date ( ) ) . getTime ( ) - from . getTime ( ) ) ; } ) . first ( N ) . value ( ) ; }
return the closest N forecasts in the future to current time with the smallest time range
return the closest N forecasts in the future to current time with the smallest time range