Created
April 12, 2018 12:42
-
-
Save liberium/e748a4c42ce7f2f51edb680c6cde8f17 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
/** | |
clientDurations = [1,2,3] | |
numTicketWindows = 2 | |
getTimeToComplete(clientDurations, numTicketWindows) // 3 | |
*/ | |
function getTimeToServeClients(clientDurations, numTicketWindows) { | |
/* Array of durations clients have spent in each ticket window. */ | |
const cumulativeDurations = new Array(numTicketWindows).fill(0) | |
clientDurations.forEach(cd => { | |
/* Let the least busy window to serve the client. */ | |
const minDurationIdx = cumulativeDurations.indexOf(Math.min(...cumulativeDurations)) | |
cumulativeDurations[minDurationIdx] += cd | |
}) | |
return Math.max(...cumulativeDurations) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment