Skip to content

Instantly share code, notes, and snippets.

@laat
Created July 25, 2022 06:21
Show Gist options
  • Save laat/8e0666e2c38377de7ceb0890afc4560a to your computer and use it in GitHub Desktop.
Save laat/8e0666e2c38377de7ceb0890afc4560a to your computer and use it in GitHub Desktop.
const sleep = (s) =>
new Promise((resolve) =>
setTimeout(() => resolve(s), s * 1000)
);
const sleepSort = async (arr) => {
const res = [];
await Promise.all(
arr
.map(sleep)
.map((x) => x.then(res.push.bind(res)))
);
return res;
};
await sleepSort([1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment