Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created May 20, 2011 08:00
Show Gist options
  • Select an option

  • Save KOBA789/982529 to your computer and use it in GitHub Desktop.

Select an option

Save KOBA789/982529 to your computer and use it in GitHub Desktop.
JavaScriptでsleep sort
function sleepSort(arr, cb) {
var c = 0, result = [];
for (var i = 0; i < arr.length; i++) {
var n = arr[i];
setTimeout(function(n) {
result.push(n);
c++;
if (c >= arr.length) {
cb(result);
}
}, n, n);
}
}
sleepSort([5, 5, 4, 2, 6], function(d) {
  alert(d);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment