Fix typos
This commit is contained in:
parent
3d009bfa14
commit
f6b9d22e68
1 changed files with 6 additions and 6 deletions
|
@ -418,7 +418,7 @@ alert(arr); // *!*1, 2, 15*/!*
|
||||||
|
|
||||||
Now it works as intended.
|
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 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.
|
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.
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ It also returns the array `arr` after the reversal.
|
||||||
|
|
||||||
### split and join
|
### split and join
|
||||||
|
|
||||||
Here's the situation from the real life. We are writing a messaging app, and the person enters the comma-delimited list of receivers: `John, Pete, Mary`. But for us an array of names would be much more comfortable than a single string. How to get it?
|
Here's the situation from real life. We are writing a messaging app, and the person enters the comma-delimited list of receivers: `John, Pete, Mary`. But for us an array of names would be much more comfortable than a single string. How to get it?
|
||||||
|
|
||||||
The [str.split(delim)](mdn:js/String/split) method does exactly that. It splits the string into an array by the given delimiter `delim`.
|
The [str.split(delim)](mdn:js/String/split) method does exactly that. It splits the string into an array by the given delimiter `delim`.
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ So far, like `forEach/map`. But there's one more argument:
|
||||||
|
|
||||||
The easiest way to grasp that is by example.
|
The easiest way to grasp that is by example.
|
||||||
|
|
||||||
Here we get a sum of array in one line:
|
Here we get a sum of an array in one line:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let arr = [1, 2, 3, 4, 5];
|
let arr = [1, 2, 3, 4, 5];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue