Skip to content

Instantly share code, notes, and snippets.

@vstarck
Created June 16, 2011 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vstarck/1029179 to your computer and use it in GitHub Desktop.
Save vstarck/1029179 to your computer and use it in GitHub Desktop.
Sleep Sort in JavaScript | http://t.co/nWJACyK
// from: http://dis.4chan.org/read/prog/1295544154/170
function sleepSort(list, callback) {
var result = [];
list.forEach(function(i) {
setTimeout(function() {
result.push(i);
if(result.length == list.length) {
callback(result);
}
}, i);
});
}
var list = [4,5,7,1,2,4,5];
sleepSort(list, alert);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment