Created
November 17, 2014 19:57
-
-
Save prettymuchbryce/ba7be74f548b9bb593a9 to your computer and use it in GitHub Desktop.
This file contains 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 data = { truck: { trips: [ { begin: 100, end: 500 }, { begin: 700, end: 1000 }, { begin: 1100, end: 1200 }, { begin: 1300, end: 2000 } ] } }; | |
function validate(array, input) { | |
for (var i = 0; i < array.truck.trips.length; i++) { | |
var trip = array.truck.trips[i]; | |
if (input.begin >= trip.begin && input.begin <= trip.end) { | |
// console.log('invalid beginning'); | |
return false; | |
} else if(input.end >= trip.begin && input.end <= trip.end) { | |
// console.log('invalid end'); | |
return false; | |
} | |
}; | |
return true; | |
} | |
console.log('501 699 should be true: ', validate(data, {begin:501, end:699})); | |
console.log('501 701 should be false:', validate(data, {begin:501, end:701})); | |
console.log('499 699 should be false:', validate(data, {begin:499, end:699})); | |
console.log('499 701 should be false:', validate(data, {begin:499, end:701})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment