Skip to content

Commit

Permalink
Finished Map and anothers
Browse files Browse the repository at this point in the history
  • Loading branch information
lksilva committed Sep 23, 2018
1 parent 8a64840 commit ca90e8d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions JS/JS-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- [Implementação do Generator](#implementação-do-generator)
- [Debouncing](#debouncing)
- [Throttle](#throttle)
- [Map、FlatMap e Reduce](#mapflatmap-and-reduce)
- [Map、FlatMap e Reduce](#mapflatmap-e-reduce)
- [Async e await](#async-and-await)
- [Proxy](#proxy)
- [Por que 0.1 + 0.2 != 0.3](#why-01--02--03)
Expand Down Expand Up @@ -1186,16 +1186,16 @@ _.throttle = function(func, wait, options) {
};
```
# Map、FlatMap and Reduce
# Map、FlatMap e Reduce
The effect of `Map` is to generate a new array, iterate over the original array, take each element out to do some transformation, and then `append` to the new array.
O efeito do `Map` é para gerar um novo array, iterando sobre o array original, tomando cada elemento para fazer alguma transformação, e então `append` para um novo array.
```js
[1, 2, 3].map((v) => v + 1)
// -> [2, 3, 4]
```
`Map` has three parameters, namely the current index element, the index, the original array.
`Map` tem três parâmetros, nomeando o índice atual do elemento, o índice, o array original.
```js
['1','2','3'].map(parseInt)
Expand All @@ -1204,14 +1204,14 @@ The effect of `Map` is to generate a new array, iterate over the original array,
// parseInt('3', 2) -> NaN
```
The effect of `FlatMap` is almost the same with a `Map`, but the original array will be flatten for multidimensional arrays. You can think of `FlatMap` as a `map` and a `flatten`, which is currently not supported in browsers.
O efeito do `FlatMap` é quase o mesmo do `Map`, mas o array original será substituído para um array multidimensional. Você pode pensar no `FlatMap` com um `map` e um `flatten`, que atualmente não é suportado nos navegadores.
```js
[1, [2], 3].flatMap((v) => v + 1)
// -> [2, 3, 4]
```
You can achieve this when you want to completely reduce the dimensions of a multidimensional array:
Você pode alcançar isso quando você quer reduzir completamente dimensões de um array multidimensional:
```js
const flattenDeep = (arr) => Array.isArray(arr)
Expand All @@ -1221,7 +1221,7 @@ const flattenDeep = (arr) => Array.isArray(arr)
flattenDeep([1, [[2], [3, [4]], 5]])
```
The effect of `Reduce` is to combine the values in the array and get a final value:
O efeito do `Reduce` é para combinar os valores em um array e pegar o valor final:
```js
function a() {
Expand Down

0 comments on commit ca90e8d

Please sign in to comment.