Created
September 25, 2017 00:15
-
-
Save evaldosantos/4af1698125a48e2bbd1492280a09fdc0 to your computer and use it in GitHub Desktop.
Escalonamento baseado em intervalo
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
// Reference: https://gist.github.com/werbet/6af175eadd85218f74ac | |
const INTERVALS = [{start:3, end: 5}, {start:0, end: 1}, {start:1, end: 2}, {start:2, end: 3}, {start:2, end: 5}]; | |
function schedule(ready){ | |
let last_end = -1 | |
let running = [] | |
let remainder = [] | |
ready | |
.map((p) => ({start: p.end, end: p.start})) | |
.sort((a, b) => a.start>= b.start) | |
.map((p) => ({start: p.end, end: p.start})) | |
.forEach(function(process) { | |
if( process.start >= last_end ) { | |
last_end = process.end | |
running.push(process); | |
} else { | |
remainder.push(process) | |
} | |
}); | |
return {running, remainder}; | |
} | |
console.log(schedule(INTERVALS)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://jsfiddle.net/767j4Lne/