Created
March 28, 2016 14:57
-
-
Save rlemon/668116821cf6604a007f to your computer and use it in GitHub Desktop.
sleep sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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