Merge pull request #2178 from vsemozhetbyt/patch-4
Correct outdated info
This commit is contained in:
commit
1a4849ac4c
1 changed files with 1 additions and 1 deletions
|
@ -419,7 +419,7 @@ Now it works as intended.
|
||||||
|
|
||||||
Let's step aside and think what's happening. The `arr` can be array of anything, right? It may contain numbers or strings or objects or whatever. We have a set of *some items*. To sort it, we need an *ordering function* that knows how to compare its elements. The default is a string order.
|
Let's step aside and think what's happening. The `arr` can be array of anything, right? It may contain numbers or strings or objects or whatever. We have a set of *some items*. To sort it, we need an *ordering function* that knows how to compare its elements. The default is a string order.
|
||||||
|
|
||||||
The `arr.sort(fn)` method implements a generic sorting algorithm. We don't need to care how it internally works (an optimized [quicksort](https://en.wikipedia.org/wiki/Quicksort) most of the time). It will walk the array, compare its elements using the provided function and reorder them, all we need is to provide the `fn` which does the comparison.
|
The `arr.sort(fn)` method implements a generic sorting algorithm. We don't need to care how it internally works (an optimized [quicksort](https://en.wikipedia.org/wiki/Quicksort) or [Timsort](https://en.wikipedia.org/wiki/Timsort) most of the time). It will walk the array, compare its elements using the provided function and reorder them, all we need is to provide the `fn` which does the comparison.
|
||||||
|
|
||||||
By the way, if we ever want to know which elements are compared -- nothing prevents from alerting them:
|
By the way, if we ever want to know which elements are compared -- nothing prevents from alerting them:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue