Created
July 28, 2017 06:17
-
-
Save SterlingChin/d7e8c5048db57c8ec8d2aed089522663 to your computer and use it in GitHub Desktop.
TruHearing Assessment
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
const day=[ | |
['8:30', '9:00'], | |
['9:00', '9:30'], | |
['9:30', '10:00'], | |
['10:00', '10:30'], | |
['10:30', '11:00'], | |
['11:00', '11:30'], | |
['11:30', '12:00'], | |
['1:00', '1:30'], | |
['1:30', '2:00'], | |
['2:00', '2:30'], | |
['2:30', '3:00'], | |
['3:00', '3:30'], | |
['3:30', '4:00'], | |
['4:00', '4:30'], | |
['4:30', '5:00'] | |
] | |
const appointments=[ | |
['9:00', '9:30'], | |
['9:00', '11:30'], | |
['10:00', '11:00'], | |
['2:30', '3:00'], | |
['2:30', '3:30'] | |
] | |
const availability = [ | |
8.5, | |
9, | |
9.5, | |
10, | |
10.5, | |
11, | |
11.5, | |
13, | |
13.5, | |
14, | |
14.5, | |
15, | |
15.5, | |
16, | |
16.5 | |
] | |
team_availability = () => { | |
const app = appointments | |
const avail = availability | |
//convert appointments | |
for(let i = 0; i < app.length; i++) { | |
for(let j = 0; j < app[i].length; j++) { | |
const split = app[i][j].split(':') | |
//convert to integers | |
if(split[1] === '30') { | |
app[i][j] = parseInt(split[0]) + .5 | |
} else { | |
app[i][j] = parseInt(split[0]) | |
} | |
//convert to 24 hr time | |
if(app[i][j] < 7) { | |
app[i][j] += 12 | |
} | |
} | |
} | |
//remove same start times | |
for(let i= 0; i < app.length-1; i++){ | |
if(app[i][0] === app[i+1][0] && app[i][1] <= app[i+1][1]) { | |
app.splice(i,1) | |
} else { | |
app.splice(i+1, 1) | |
} | |
} | |
//check end times and remove overlapping periods | |
for(let i= 0; i < app.length-1; i++){ | |
if(app[i][1] > app[i+1][1]){ | |
app.splice(i+1, 1) | |
} | |
} | |
//remove unavailable times from availability | |
for(let i=app.length-1; i >= 0; i--){ | |
let start = avail.indexOf(app[i][0]) | |
let end = avail.indexOf(app[i][1]) | |
day.splice(start, (end - start)) | |
} | |
return day | |
} | |
team_availability() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can also be run here: repl.it
I have various versions of this assessment saved on repl.it. I chose to go with this option because I'm going to need to explain my thought process to another developer and using more vanilla js allows me to describe it more thoroughly. Prior to going to prod, this code could be cleaned up, comments removed, etc.
I have a (somewhat) cleaned up version using ES6 here: repl.it