Skip to content

Instantly share code, notes, and snippets.

@freddiefujiwara
Created January 13, 2012 00:15
Show Gist options
  • Select an option

  • Save freddiefujiwara/1603945 to your computer and use it in GitHub Desktop.

Select an option

Save freddiefujiwara/1603945 to your computer and use it in GitHub Desktop.
jobs
var i=0,t=0,answer=[],jobs=[{id:1,s:1,t:3},{id:2,s:2,t:5},{id:3,s:4,t:7},{id:4,s:6,t:9},{id:5,s:8,t:10}];
jobs.sort(function(a,b) {return a.t-b.t;});
for(;i<jobs.length;i++){
if(t<jobs[i].s){
answer.push(jobs[i]);
t=jobs[i].t;
}
}
console.log(answer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment