Fix some possible typos and omissions in 1.5.5

This commit is contained in:
Vse Mozhe Buty 2020-10-09 23:46:13 +03:00 committed by GitHub
parent edef0b4306
commit 858ad69e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,7 +44,7 @@ The syntax is:
arr.splice(start[, deleteCount, elem1, ..., elemN]) arr.splice(start[, deleteCount, elem1, ..., elemN])
``` ```
It modified `arr` starting from the index `start`: removes `deleteCount` elements and then inserts `elem1, ..., elemN` at their place. Returns the array of removed elements. It modifies `arr` starting from the index `start`: removes `deleteCount` elements and then inserts `elem1, ..., elemN` at their place. Returns the array of removed elements.
This method is easy to grasp by examples. This method is easy to grasp by examples.
@ -700,7 +700,7 @@ alert(soldiers[1].age); // 23
If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error. If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error.
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The former is used more often, as it's a bit easier to understand for most people. A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The latter is used more often, as it's a bit easier to understand for most people.
## Summary ## Summary
@ -711,7 +711,7 @@ A cheat sheet of array methods:
- `pop()` -- extracts an item from the end, - `pop()` -- extracts an item from the end,
- `shift()` -- extracts an item from the beginning, - `shift()` -- extracts an item from the beginning,
- `unshift(...items)` -- adds items to the beginning. - `unshift(...items)` -- adds items to the beginning.
- `splice(pos, deleteCount, ...items)` -- at index `pos` delete `deleteCount` elements and insert `items`. - `splice(pos, deleteCount, ...items)` -- at index `pos` deletes `deleteCount` elements and inserts `items`.
- `slice(start, end)` -- creates a new array, copies elements from index `start` till `end` (not inclusive) into it. - `slice(start, end)` -- creates a new array, copies elements from index `start` till `end` (not inclusive) into it.
- `concat(...items)` -- returns a new array: copies all members of the current one and adds `items` to it. If any of `items` is an array, then its elements are taken. - `concat(...items)` -- returns a new array: copies all members of the current one and adds `items` to it. If any of `items` is an array, then its elements are taken.
@ -729,7 +729,7 @@ A cheat sheet of array methods:
- `sort(func)` -- sorts the array in-place, then returns it. - `sort(func)` -- sorts the array in-place, then returns it.
- `reverse()` -- reverses the array in-place, then returns it. - `reverse()` -- reverses the array in-place, then returns it.
- `split/join` -- convert a string to array and back. - `split/join` -- convert a string to array and back.
- `reduce(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls. - `reduce/reduceRight(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls.
- Additionally: - Additionally:
- `Array.isArray(arr)` checks `arr` for being an array. - `Array.isArray(arr)` checks `arr` for being an array.
@ -738,7 +738,7 @@ Please note that methods `sort`, `reverse` and `splice` modify the array itself.
These methods are the most used ones, they cover 99% of use cases. But there are few others: These methods are the most used ones, they cover 99% of use cases. But there are few others:
- [arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every) checks the array. - [arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every) check the array.
The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`. The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`.