Created
May 5, 2016 00:49
-
-
Save suuuzi/6ed92e535c26800b096cd8b3018e852b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hoursOk = {"slotTimes": [ | |
{"hourIni": "10:00", "hourEnd": "11:00"}, | |
{"hourIni":"13:00", "hourEnd": "15:00"}, | |
{"hourIni":"17:00", "hourEnd": "22:00"} | |
]}; | |
var hoursErrado = {"slotTimes": [ | |
{"hourIni": "10:00", "hourEnd": "11:00"}, | |
{"hourIni":"13:00", "hourEnd": "15:00"}, | |
{"hourIni":"13:30", "hourEnd": "22:00"} | |
]}; | |
var convertHourToMinutes = function(hrs) { | |
var parts = hrs.split(":"); | |
return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10); | |
} | |
var convertHoursArrayToMinutesArray = function(arr){ | |
for(var i = 0; i < arr.slotTimes.length; i++){ | |
arr.slotTimes[i].hourIni = convertHourToMinutes(arr.slotTimes[i].hourIni); | |
arr.slotTimes[i].hourEnd = convertHourToMinutes(arr.slotTimes[i].hourEnd); | |
} | |
} | |
var intersect = function(x1,x2,y1,y2){ | |
return x1 < y2 && y1 < x2; | |
} | |
var checkIntersect = function(arr){ | |
//console.log(arr); | |
for(var i = 0; i < arr.length; i++){ | |
for(var j = 0; j < arr.length; j++){ | |
if(j === i) { | |
continue; | |
} | |
console.log(arr[i]); | |
console.log(arr[j]); | |
if( intersect(arr[i].hourIni, arr[i].hourEnd, arr[j].hourIni, arr[j].hourEnd)){ | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
convertHoursArrayToMinutesArray(hoursOk); | |
console.log(checkIntersect(hoursOk.slotTimes) ? "tem sobreposicao" : "nao tem"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment