{"size": 1257, "ext": "js", "max_stars_repo_path": "controllers/scheduler.js", "max_stars_repo_name": "DefCon-init/hubspot-coding", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "controllers/scheduler.js", "max_issues_repo_name": "DefCon-init/hubspot-coding", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controllers/scheduler.js", "max_forks_repo_name": "DefCon-init/hubspot-coding", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.5681818182, "max_line_length": 93, "alphanum_fraction": 0.5672235481}
const moment = require('moment')
const _ = require('lodash');

class Scheduler {
    constructor() {
        this.days = 366;
        this.dates = [];
        this.beginningOfYear = moment('2017-01-01');

        for (let i = 0; i < this.days; i++) {
            this.dates.push([]);
        }
    }

    mapDateToIndex = date => date.diff(this.beginningOfYear, 'days');

    getBestDate = () => {
        let maxCount = 0;
        let startDate = null;

        let previousCount = this.dates[0].length;

        for (let i = 1; i < this.days; i++) {
            let currentCount = this.dates[i].length;
            let attendBothDays = _.intersection(this.dates[i], this.dates[i - 1])
            let attendingCount = attendBothDays.length;

            if (attendingCount > maxCount && currentCount > 0 && previousCount > 0) {
                maxCount = attendingCount;
                startDate = moment(this.beginningOfYear).add(i - 1, 'days');
            }

            previousCount = currentCount;
        }

        return startDate;
    }

    pushToArray = (email, date) => this.dates[this.mapDateToIndex(moment(date))].push(email);

    getAttendeesForDate = (date) => this.dates[this.mapDateToIndex(moment(date))]
}

module.exports = Scheduler