typo
This commit is contained in:
parent
2908fe7fe6
commit
ab7cd2d14e
1 changed files with 1 additions and 1 deletions
|
@ -382,7 +382,7 @@ alert(arr); // *!*1, 2, 15*/!*
|
|||
|
||||
Now it works as intended.
|
||||
|
||||
Let's step aside and thing what's happening. The `arr` can be array of anything, right? It may contain numbers or strings or html elements or whatever. We have a set of *something*. 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 html elements or whatever. We have a set of *something*. 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 has a built-in implementation of sorting algorithm. We don't need to care how it exactly 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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue