Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created March 28, 2016 14:57
Show Gist options
  • Save rlemon/668116821cf6604a007f to your computer and use it in GitHub Desktop.
Save rlemon/668116821cf6604a007f to your computer and use it in GitHub Desktop.
sleep sort
function sleepSort(stack) {
return new Promise( (resolve, reject) => {
let ret = [], len = stack.length;
const org = item => setTimeout(adder.bind(null, item), item);
const adder = item => ret.push(item) && ( (--len <= 0) && resolve(ret) );
stack.forEach(org);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment