I like asynchronous nature of javascript because it helps me to sort arrays easily. No more bubble, selection, merge or quick sort algorithms. Timeout sort for the win!
James is a JavaScript Developer, Speaker, and Teacher with a passion for teaching developers through content.Β He is a full-time Technical Content Creator with years of experience in Software Developme
I love to build software. I love working with people to do things bigger than I could accomplish alone. Iβm motivated by big problems, and I think if youβve got some here, I can help solve.
In the course I'm doing we had to use setTimeout as a way to avoid stack overflow. I don't think I'd ever do it in a real app, but it was an interesting trick.
I am Nandan, and you probably know me as the Software Engineer who "Hacked" an airline to retrieve his luggage. I write about Fron-End, Git, Security, DevOps, etc.
Well, it's a joke and shouldn't be used anywhere in production code.
We iterate on every element (N) in array of numbers and ask a JS engine to log this number in the console after N milliseconds from now. So, these numbers will be logged in a sorted way, because time in our universe flows in one direction π
I am Nandan, and you probably know me as the Software Engineer who "Hacked" an airline to retrieve his luggage. I write about Fron-End, Git, Security, DevOps, etc.
Yes, indeed it's a joke and should not be used anywhere in production. But it's nice to know how things work, It took me some time to figure out but it was worth it.
Thanks π
I like asynchronous nature of javascript because it helps me to sort arrays easily. No more bubble, selection, merge or quick sort algorithms. Timeout sort for the win!
π€£π€£π€£
This is amazing lol
I think you are a bit crazy, bro ;)
Unfortunatelly, this cute sorting algorithm doesn't work on values that < 1.
It also poorly works with floats (ex.
[1.5, 1.4, 1.3, 1.2, 1.1]
) and big numbers πIt has limitation that if any item of array contained number in billion or millions it will keep in waiting unless the time finish.
how does it sort with timeout? should it not pick items with index
This is called timeout sort I think :D
did a flex-box version: jsfiddle.net/bradleygriffith/2dsag...
Ahaha, awesome! π
half a second sort for 5 items, very quickly
It's amazing
good work
In the course I'm doing we had to use setTimeout as a way to avoid stack overflow. I don't think I'd ever do it in a real app, but it was an interesting trick.
Hey Eugene,
Would you please help me understand how does this happen. Any link or reference would be very helpful.
TIA :)
Well, it's a joke and shouldn't be used anywhere in production code.
We iterate on every element (N) in array of numbers and ask a JS engine to log this number in the console after N milliseconds from now. So, these numbers will be logged in a sorted way, because time in our universe flows in one direction π
Yes, indeed it's a joke and should not be used anywhere in production. But it's nice to know how things work, It took me some time to figure out but it was worth it.
Thanks π
genius
This is mostly equivlant with the following code