File tree Expand file tree Collapse file tree 10 files changed +197
-199
lines changed
1-js/04-object-basics/01-object Expand file tree Collapse file tree 10 files changed +197
-199
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ importance: 5
2
2
3
3
---
4
4
5
- # Hello, object
5
+ # Hola, objeto
6
6
7
- Write the code, one line for each action:
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.
7
+ Escribe el código, una línea para cada acción:
14
8
9
+ 1 . Crea un objeto ` user ` vacío.
10
+ 2 . Agrega la propiedad ` name ` con el valor ` John ` .
11
+ 3 . Agrega la propiedad ` surname ` con el valor ` Smith ` .
12
+ 4 . Cambia el valor de ` name ` a ` Pete ` .
13
+ 5 . Remueve la propiedad ` name ` del objeto.
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
+ // Si el bucle ha comenzado quiere decir que sí hay al menos una propiedad
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 true para un objeto vacío " , function ( ) {
3
3
assert . isTrue ( isEmpty ( { } ) ) ;
4
4
} ) ;
5
5
6
- it ( "returns false if a property exists " , function ( ) {
6
+ it ( "retorna false si existe una propiedad " , 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
+ Solo crea un bucle sobre el objeto y, si hay al menos una propiedad, devuelve ` false ` inmediatamente .
Original file line number Diff line number Diff line change @@ -2,18 +2,18 @@ importance: 5
2
2
3
3
---
4
4
5
- # Check for emptiness
5
+ # Verificar los vacíos
6
6
7
- Write the function ` isEmpty(obj) ` which returns ` true ` if the object has no properties, ` false ` otherwise .
7
+ Escribe la función ` isEmpty(obj) ` que devuelva el valor ` true ` si el objeto no tiene propiedades, en caso contrario ` false ` .
8
8
9
- Should work like that :
9
+ Debería funcionar así :
10
10
11
11
``` js
12
12
let schedule = {};
13
13
14
14
alert ( isEmpty (schedule) ); // true
15
15
16
- schedule[" 8:30" ] = " get up " ;
16
+ schedule[" 8:30" ] = " Hora de levantarse " ;
17
17
18
18
alert ( isEmpty (schedule) ); // false
19
19
```
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
+ # Suma de propiedades de un objeto
6
6
7
- We have an object storing salaries of our team :
7
+ Tenemos un objeto que almacena los salarios de nuestro equipo :
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
+ Escribe el código para sumar todos los salarios y almacenarl el resultado en la variable ` sum ` . En el ejemplo de arriba nos debería dar ` 390 ` .
18
18
19
- If ` salaries ` is empty, then the result must be ` 0 ` .
19
+ Si ` salaries ` está vacio entonces el resultado 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 : "Mi menú "
5
5
} ;
6
6
7
7
8
8
function multiplyNumeric ( obj ) {
9
9
10
- /* your code */
10
+ /* tu 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 ) ;
17
-
16
+ alert ( "ancho del menú=" + menu . width + " alto=" + menu . height + " título=" + menu . title ) ;
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 ( "multiplicar todas las propiedades numéricas por 2" , function ( ) {
3
3
let menu = {
4
4
width : 200 ,
5
5
height : 300 ,
6
- title : "My menu "
6
+ title : "Mi menú "
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 , "Mi menú " ) ;
12
12
} ) ;
13
13
14
- it ( "returns nothing " , function ( ) {
14
+ it ( "No devuelve nada " , function ( ) {
15
15
assert . isUndefined ( multiplyNumeric ( { } ) ) ;
16
16
} ) ;
17
17
Original file line number Diff line number Diff line change @@ -2,32 +2,32 @@ importance: 3
2
2
3
3
---
4
4
5
- # Multiply numeric properties by 2
5
+ # Multiplicar propiedades numéricas por 2
6
6
7
- Create a function ` multiplyNumeric(obj) ` that multiplies all numeric properties of ` obj ` by ` 2 ` .
7
+ Crea una función ` multiplyNumeric(obj) ` que multiplique todas las propiedades numéricas de ` obj ` por ` 2 ` .
8
8
9
- For instance :
9
+ Por ejemplo :
10
10
11
11
``` js
12
- // before the call
12
+ // Antes de la llamada
13
13
let menu = {
14
14
width: 200 ,
15
15
height: 300 ,
16
- title: " My menu "
16
+ title: " Mi menú "
17
17
};
18
18
19
19
multiplyNumeric (menu);
20
20
21
- // after the call
21
+ // Después de la llamada
22
22
menu = {
23
23
width: 400 ,
24
24
height: 600 ,
25
- title: " My menu "
25
+ title: " Mi menú "
26
26
};
27
27
```
28
28
29
- Please note that ` multiplyNumeric ` does not need to return anything. It should modify the object in-place .
29
+ Nota que ` multiplyNumeric ` no necesita devolver nada. Debe modificar el objeto en su lugar .
30
30
31
- P.S. Use ` typeof ` to check for a number here .
31
+ P.D. Usa ` typeof ` para verificar si hay un número aquí .
32
32
33
33
You can’t perform that action at this time.
0 commit comments