Last active
February 27, 2021 22:32
-
-
Save karpolan/dda2276221b07ebeca20a38e39e1107f to your computer and use it in GitHub Desktop.
Sorting of array in O(max(array)) complicity!
This file contains hidden or 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
const source = [20, 5, 100, 1, 90, 200, 40, 29]; | |
const sorted = []; | |
console.log('source:', source); | |
for (const value of source) { | |
setTimeout(() => { | |
sorted.push(value); | |
console.log('sorting:', value); // to see progress | |
}, value); | |
} | |
setTimeout(() => { | |
console.log('sorted:', sorted); | |
}, Math.max(...source) + 42); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment