You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
421
+
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.
422
422
423
423
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.
424
424
@@ -474,7 +474,7 @@ It also returns the array `arr` after the reversal.
474
474
475
475
### split and join
476
476
477
-
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?
477
+
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?
478
478
479
479
The [str.split(delim)](mdn:js/String/split) method does exactly that. It splits the string into an array by the given delimiter `delim`.
480
480
@@ -548,7 +548,7 @@ So far, like `forEach/map`. But there's one more argument:
548
548
549
549
The easiest way to grasp that is by example.
550
550
551
-
Here we get a sum of array in one line:
551
+
Here we get a sum of an array in one line:
552
552
553
553
```js run
554
554
let arr = [1, 2, 3, 4, 5];
@@ -681,7 +681,7 @@ In the call above, we use `user.younger` as a filter and also provide `user` as
681
681
682
682
## Summary
683
683
684
-
A cheatsheet of array methods:
684
+
A cheat sheet of array methods:
685
685
686
686
- To add/remove elements:
687
687
-`push(...items)` -- adds items to the end,
@@ -727,6 +727,6 @@ For the full list, see the [manual](mdn:js/Array).
727
727
728
728
From the first sight it may seem that there are so many methods, quite difficult to remember. But actually that's much easier than it seems.
729
729
730
-
Look through the cheatsheet just to be aware of them. Then solve the tasks of this chapter to practice, so that you have experience with array methods.
730
+
Look through the cheat sheet just to be aware of them. Then solve the tasks of this chapter to practice, so that you have experience with array methods.
731
731
732
-
Afterwards whenever you need to do something with an array, and you don't know how -- come here, look at the cheatsheet and find the right method. Examples will help you to write it correctly. Soon you'll automatically remember the methods, without specific efforts from your side.
732
+
Afterwards whenever you need to do something with an array, and you don't know how -- come here, look at the cheat sheet and find the right method. Examples will help you to write it correctly. Soon you'll automatically remember the methods, without specific efforts from your side.
0 commit comments