Skip to content

Instantly share code, notes, and snippets.

@FlorianWendelborn
Created October 9, 2018 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianWendelborn/b2460266b1a4121ef8d45b16a0bb66e8 to your computer and use it in GitHub Desktop.
Save FlorianWendelborn/b2460266b1a4121ef8d45b16a0bb66e8 to your computer and use it in GitHub Desktop.
const appointments = [[100, 125], [200, 230], [230, 400]]
const requests = [[10, 50], [130, 210], [240, 250]]
const times = [[0]]
for (let i = 0; i < appointments.length; i++) {
const [ra, rb] = appointments[i]
const last = times[times.length - 1]
last[1] = ra
times.push([rb])
}
const results = requests.filter(([a, b]) => {
for (let i = 0; i < times.length; i++) {
const [x, y] = times[i]
if (a >= x && b <= y) return true
}
return false
})
console.log(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment