File tree 14 files changed +281
-289
lines changed
14 files changed +281
-289
lines changed Original file line number Diff line number Diff line change 1
1
2
-
3
2
``` js
4
3
let user = {};
5
4
user .name = " John" ;
6
5
user .surname = " Smith" ;
7
6
user .name = " Pete" ;
8
7
delete user .name ;
9
8
```
10
-
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ importance: 5
2
2
3
3
---
4
4
5
- # Hello, object
5
+ # Olá, objeto
6
6
7
- Write the code, one line for each action :
7
+ Escreva o código, uma ação por linha :
8
8
9
- 1 . Create an empty object ` user ` .
10
- 2 . Add the property ` name ` with the value ` John ` .
11
- 3 . Add the property ` surname ` with the value ` Smith ` .
12
- 4 . Change the value of the ` name ` to ` Pete ` .
13
- 5 . Remove the property ` name ` from the object .
9
+ 1 . Crie um objeto vazio ( * empty object* ) ` user ` .
10
+ 2 . Adicione a propriedade ` name ` com o valor ` John ` .
11
+ 3 . Adicione a propriedade ` surname ` com o valor ` Smith ` .
12
+ 4 . Altere o valor de ` name ` para ` Pete ` .
13
+ 5 . Remova a propriedade ` name ` do objeto .
14
14
Original file line number Diff line number Diff line change 1
1
function isEmpty ( obj ) {
2
2
for ( let key in obj ) {
3
- // if the loop has started, there is a property
3
+ // se o laço começou, existe uma propriedade
4
4
return false ;
5
5
}
6
6
return true ;
Original file line number Diff line number Diff line change 1
1
describe ( "isEmpty" , function ( ) {
2
- it ( "returns true for an empty object " , function ( ) {
2
+ it ( "retorna verdadeiro para um objeto vazio " , function ( ) {
3
3
assert . isTrue ( isEmpty ( { } ) ) ;
4
4
} ) ;
5
5
6
- it ( "returns false if a property exists " , function ( ) {
6
+ it ( "retorna falso se uma propriedade existir " , function ( ) {
7
7
assert . isFalse ( isEmpty ( {
8
8
anything : false
9
9
} ) ) ;
Original file line number Diff line number Diff line change 1
- Just loop over the object and ` return false ` immediately if there's at least one property .
1
+ Simplemente, percorra ( * loop over* ) o objeto e imediatamente ` return false ` se pelo menos houver uma propriedade .
Original file line number Diff line number Diff line change @@ -2,19 +2,18 @@ importance: 5
2
2
3
3
---
4
4
5
- # Check for emptiness
5
+ # Verifique por vazio ( * emptiness* )
6
6
7
- Write the function ` isEmpty(obj) ` which returns ` true ` if the object has no properties, ` false ` otherwise.
8
-
9
- Should work like that:
7
+ Escreva a função ` isEmpty(obj) ` , que retorna ` true ` se o objeto não tiver propriedades, e ` false ` caso contrário.
10
8
9
+ Deve assim funcionar:
11
10
``` js
12
11
let schedule = {};
13
12
14
- alert ( isEmpty (schedule) ); // true
13
+ alert ( isEmpty (schedule) ); // verdadeiro
15
14
16
- schedule[" 8:30" ] = " get up " ;
15
+ schedule[" 8:30" ] = " levante-se " ;
17
16
18
- alert ( isEmpty (schedule) ); // false
17
+ alert ( isEmpty (schedule) ); // falso
19
18
```
20
19
Original file line number Diff line number Diff line change 1
- Sure, it works, no problem .
1
+ Com certeza, funciona, sem problemas .
2
2
3
- The ` const ` only protects the variable itself from changing .
3
+ A ` const ` apenas protege a própria variável contra alterações .
4
4
5
- In other words , ` user ` stores a reference to the object. And it can't be changed. But the content of the object can .
5
+ Por outras palavras , ` user ` armazena uma referência ao objeto. E não pode ser alterada. Mas, o conteúdo do objeto pode .
6
6
7
7
``` js run
8
8
const user = {
9
9
name: " John"
10
10
};
11
11
12
12
* ! *
13
- // works
13
+ // funciona
14
14
user .name = " Pete" ;
15
15
*/ ! *
16
16
17
- // error
17
+ // erro
18
18
user = 123 ;
19
19
```
Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ importance: 5
2
2
3
3
---
4
4
5
- # Constant objects ?
5
+ # Objetos constantes ?
6
6
7
- Is it possible to change an object declared with ` const ` ? What do you think ?
7
+ É possível alterar um objeto declarado com ` const ` ? O que acha ?
8
8
9
9
``` js
10
10
const user = {
11
11
name: " John"
12
12
};
13
13
14
14
* ! *
15
- // does it work ?
15
+ // isto funciona ?
16
16
user .name = " Pete" ;
17
17
*/ ! *
18
18
```
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ importance: 5
2
2
3
3
---
4
4
5
- # Sum object properties
5
+ # Soma das propriedades de um objeto
6
6
7
- We have an object storing salaries of our team :
7
+ Temos um objeto armazenando salários da nossa equipa :
8
8
9
9
``` js
10
10
let salaries = {
@@ -14,6 +14,6 @@ let salaries = {
14
14
}
15
15
```
16
16
17
- Write the code to sum all salaries and store in the variable ` sum ` . Should be ` 390 ` in the example above .
17
+ Escreva o código para somar todos os salários e armazenar na variável ` sum ` . Para o exemplo acima, deverá ser ` 390 ` .
18
18
19
- If ` salaries ` is empty, then the result must be ` 0 ` .
19
+ Se ` salaries ` for vazio, então o resultado deve ser ` 0 ` .
Original file line number Diff line number Diff line change 1
1
let menu = {
2
2
width : 200 ,
3
3
height : 300 ,
4
- title : "My menu"
4
+ title : "O meu menu"
5
5
} ;
6
6
7
7
8
8
function multiplyNumeric ( obj ) {
9
9
10
- /* your code */
10
+ /* o seu código */
11
11
12
12
}
13
13
14
14
multiplyNumeric ( menu ) ;
15
15
16
- alert ( "menu width =" + menu . width + " height =" + menu . height + " title =" + menu . title ) ;
16
+ alert ( "largura do menu =" + menu . width + " altura =" + menu . height + " título =" + menu . title ) ;
17
17
Original file line number Diff line number Diff line change 1
1
describe ( "multiplyNumeric" , function ( ) {
2
- it ( "multiplies all numeric properties by 2" , function ( ) {
2
+ it ( "multiplica todas as propriedades numéricas por 2" , function ( ) {
3
3
let menu = {
4
4
width : 200 ,
5
5
height : 300 ,
6
- title : "My menu"
6
+ title : "O meu menu"
7
7
} ;
8
8
let result = multiplyNumeric ( menu ) ;
9
9
assert . equal ( menu . width , 400 ) ;
10
10
assert . equal ( menu . height , 600 ) ;
11
- assert . equal ( menu . title , "My menu" ) ;
11
+ assert . equal ( menu . title , "O meu menu" ) ;
12
12
} ) ;
13
13
14
- it ( "returns nothing " , function ( ) {
14
+ it ( "não retorna nada " , function ( ) {
15
15
assert . isUndefined ( multiplyNumeric ( { } ) ) ;
16
16
} ) ;
17
17
Original file line number Diff line number Diff line change @@ -2,32 +2,30 @@ importance: 3
2
2
3
3
---
4
4
5
- # Multiply numeric properties by 2
5
+ # Multiplica as propriedades numéricas por 2
6
6
7
- Create a function ` multiplyNumeric(obj) ` that multiplies all numeric properties of ` obj ` by ` 2 ` .
7
+ Crie uma função ` multiplyNumeric(obj) ` que multiplica todas as proriedades numéricas de ` obj ` por ` 2 ` .
8
8
9
- For instance :
9
+ Por exemplo :
10
10
11
11
``` js
12
- // before the call
12
+ // antes da chamada
13
13
let menu = {
14
14
width: 200 ,
15
15
height: 300 ,
16
- title: " My menu"
16
+ title: " O meu menu"
17
17
};
18
18
19
19
multiplyNumeric (menu);
20
20
21
- // after the call
21
+ // depois da chamada
22
22
menu = {
23
23
width: 400 ,
24
24
height: 600 ,
25
- title: " My menu"
25
+ title: " O meu menu"
26
26
};
27
27
```
28
28
29
- Please note that ` multiplyNumeric ` does not need to return anything. It should modify the object in-place.
30
-
31
- P.S. Use ` typeof ` to check for a number here.
32
-
29
+ Por favor, note que ` multiplyNumeric ` não precisa de retornar nada. Deve modificar o próprio objecto.
33
30
31
+ P.S. Use ` typeof ` para verificar por um número aqui.
You can’t perform that action at this time.
0 commit comments