Naming improvement

This commit is contained in:
Mojtaba Javan 2018-12-27 07:04:00 +03:30 committed by GitHub
parent dde3c1a00b
commit 2cff9517be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -529,7 +529,7 @@ The methods [arr.reduce](mdn:js/Array/reduce) and [arr.reduceRight](mdn:js/Array
The syntax is: The syntax is:
```js ```js
let value = arr.reduce(function(previousValue, item, index, arr) { let value = arr.reduce(function(previousValue, item, index, array) {
// ... // ...
}, initial); }, initial);
``` ```
@ -538,7 +538,7 @@ The function is applied to the elements. You may notice the familiar arguments,
- `item` -- is the current array item. - `item` -- is the current array item.
- `index` -- is its position. - `index` -- is its position.
- `arr` -- is the array. - `array` -- is the array.
So far, like `forEach/map`. But there's one more argument: So far, like `forEach/map`. But there's one more argument:
@ -613,6 +613,7 @@ So it's advised to always specify the initial value.
The method [arr.reduceRight](mdn:js/Array/reduceRight) does the same, but goes from right to left. The method [arr.reduceRight](mdn:js/Array/reduceRight) does the same, but goes from right to left.
## Array.isArray ## Array.isArray
Arrays do not form a separate language type. They are based on objects. Arrays do not form a separate language type. They are based on objects.
@ -694,6 +695,9 @@ A cheatsheet of array methods:
- `includes(value)` -- returns `true` if the array has `value`, otherwise `false`. - `includes(value)` -- returns `true` if the array has `value`, otherwise `false`.
- `find/filter(func)` -- filter elements through the function, return first/all values that make it return `true`. - `find/filter(func)` -- filter elements through the function, return first/all values that make it return `true`.
- `findIndex` is like `find`, but returns the index instead of a value. - `findIndex` is like `find`, but returns the index instead of a value.
- To iterate over elements:
- `forEach(func)` -- calls `func` for every element, does not return anything.
- To transform the array: - To transform the array:
- `map(func)` -- creates a new array from results of calling `func` for every element. - `map(func)` -- creates a new array from results of calling `func` for every element.
@ -702,9 +706,6 @@ A cheatsheet of array methods:
- `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(func, initial)` -- calculate a single value over the array by calling `func` for each element and passing an intermediate result between the calls.
- To iterate over elements:
- `forEach(func)` -- calls `func` for every element, does not return anything.
- Additionally: - Additionally:
- `Array.isArray(arr)` checks `arr` for being an array. - `Array.isArray(arr)` checks `arr` for being an array.