When I see a post on a similar topic on any social network, there are almost always a lot of comments of this type under it:
Why do you need to know this if there are built-in sorting methods?
Why reinvent the wheel?
It is necessary to pass an interview, objectively there is no need to know it anymore
In "any javascript engine" they are not stupid, and have already done everything right
And I myself used to think the same way until I came to one of the Rostelecom IT teams as a frontend developer. Together we came across a very interesting case: it was necessary to create a widget that could be built into the information systems of all our macro-regional branches and simplify the work of operators in selecting the optimal tariff.
Straight to the point
What do you think will happen after this code is executed? In the meantime, there is no need to know about it. β
It seems that nothing strange, but there are nuances.
Case number times
, , , unit-. - . . -, . , Node.js 10, , . , , . , β . , , , , .
. Node , Node, 11, . . Node 12, .
: Google Chrome 80 , 69 β . , .
,
Release notes Google Chrome
, Google Chrome 69 β , 6- V8
Release notes V8
6 7 V8
Getting things sorted in V8, , 7- V8 TimSort, QuickSort. , , - .
Node.js 10.22 ( V8 v6.8) QuickSort.β
β , , 0.
Node.js 14.5 ( V8 v7.0) TimSort.β
β .
? , JavaScript. Node.js , .
, . BlockSort (wikisort). , , , , .
:
lodash.sortby
WikiSort javascript (WikiSort)
QuickSort V8 (node.js 10.22.0)
TimSort V8 (node.js 14.5.0)
10 , 100 .
β
β : , V8, WikiSort TimSort, . lodash .
sort-test-js, β Tihon-Ustinov/sort-test-js
?
| JavaScript | |||
Node.js | 11.0.0 | 2018-10-23 | V8 7.0.276.28 | + |
Node.js | 10.22.0 | 2020-07-21 | V8 6.8.275.32 | - |
Google Chrome | 70.0.3538 | 2018-10-16 | V8 7.0.276 | + |
Google Chrome | 69.0.3497 | 2018-09-04 | V8 6.9.427 | - |
Β« JavaScriptΒ»,
,
,
, ,