JS get wednesday

by Marco Abate

JavaScript

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);

function getWednesday() {
    var d = new Date(),
        month = d.getMonth(),
        mondays = [];

    d.setDate(1);

    // Get the first Monday in the month
    while (d.getDay() !== 3) {
        d.setDate(d.getDate() + 3);
    }

    // Get all the other Mondays in the month
    while (d.getMonth() === month) {
        mondays.push(new Date(d.getTime()).toString());
        d.setDate(d.getDate() + 7);
    }

    return mondays;
}

console.log(getWednesday());
console.log(today);
console.log(tomorrow);
console.log(yesterday);

console.log(getWednesday().indexOf(yesterday.toString()));