Skip to content

Instantly share code, notes, and snippets.

@evaldosantos
Created September 25, 2017 00:15
Show Gist options
  • Save evaldosantos/4af1698125a48e2bbd1492280a09fdc0 to your computer and use it in GitHub Desktop.
Save evaldosantos/4af1698125a48e2bbd1492280a09fdc0 to your computer and use it in GitHub Desktop.
Escalonamento baseado em intervalo
// 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));
@evaldosantos
Copy link
Author

@evaldosantos
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment