Skip to content

Instantly share code, notes, and snippets.

@liberium
Created April 12, 2018 12:42
Show Gist options
  • Save liberium/e748a4c42ce7f2f51edb680c6cde8f17 to your computer and use it in GitHub Desktop.
Save liberium/e748a4c42ce7f2f51edb680c6cde8f17 to your computer and use it in GitHub Desktop.
/**
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