Skip to main content
edited title
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Get all remaining specific days of the week in javasript

edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
added 1 character in body
Source Link
Almis
  • 299
  • 3
  • 11

What this function does it's to return an array of remaining dates that are e.g. Mondays. Is this really the best way to do that?

function range(start, count) {
    return Array.apply(0, Array(count))
                .map(function (element, index) { 
                         return index + start;  
                     });
}

function GetAllRemainingDaysOfTheWeek(day)
{
    var today = new Date();
    var last = new Date(today.getFullYear(), 11, 31);
    today = new Date(today.getFullYear(), today.getMonth(), today.getDaygetDate());
    var diffInDays = (last.getTime() - today.getTime()) / (1000 * 3600 * 24);
    
    return range(1, diffInDays+1).map(function(x) {
       return new Date(today.getFullYear(), today.getMonth(), today.getDay()+x);
    }).filter(function(x){
       if(x.getDay() == 1) return true;
    });
}

What this function does it's to return an array of remaining dates that are e.g. Mondays. Is this really the best way to do that?

function range(start, count) {
    return Array.apply(0, Array(count))
                .map(function (element, index) { 
                         return index + start;  
                     });
}

function GetAllRemainingDaysOfTheWeek(day)
{
    var today = new Date();
    var last = new Date(today.getFullYear(), 11, 31);
    today = new Date(today.getFullYear(), today.getMonth(), today.getDay());
    var diffInDays = (last.getTime() - today.getTime()) / (1000 * 3600 * 24);
    
    return range(1, diffInDays+1).map(function(x) {
       return new Date(today.getFullYear(), today.getMonth(), today.getDay()+x);
    }).filter(function(x){
       if(x.getDay() == 1) return true;
    });
}

What this function does it's to return an array of remaining dates that are e.g. Mondays. Is this really the best way to do that?

function range(start, count) {
    return Array.apply(0, Array(count))
                .map(function (element, index) { 
                         return index + start;  
                     });
}

function GetAllRemainingDaysOfTheWeek(day)
{
    var today = new Date();
    var last = new Date(today.getFullYear(), 11, 31);
    today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    var diffInDays = (last.getTime() - today.getTime()) / (1000 * 3600 * 24);
    
    return range(1, diffInDays+1).map(function(x) {
       return new Date(today.getFullYear(), today.getMonth(), today.getDay()+x);
    }).filter(function(x){
       if(x.getDay() == 1) return true;
    });
}
Source Link
Almis
  • 299
  • 3
  • 11
Loading