My Calendar II LeetCode solution in JavaScript
1var MyCalendarTwo = function () {2this.calendar = [];3this.overlaps = [];4};56/**7* @param {number} start8* @param {number} end9* @return {boolean}10*/11MyCalendarTwo.prototype.book = function (start, end) {12for (let date of this.overlaps) {13if (start < date[1] && end > date[0]) return false;14}1516for (let date of this.calendar) {17if (start < date[1] && end > date[0]) {18this.overlaps.push([Math.max(date[0], start), Math.min(date[1], end)]);19}20}21this.calendar.push([start, end]);22return true;23};