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
22
33---
44
5- # Hello, object
5+ # Hola, objeto
66
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:
148
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 11function isEmpty ( obj ) {
22 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
44 return false ;
55 }
66 return true ;
Original file line number Diff line number Diff line change 11describe ( "isEmpty" , function ( ) {
2- it ( "returns true for an empty object " , function ( ) {
2+ it ( "retorna true para un objeto vacío " , function ( ) {
33 assert . isTrue ( isEmpty ( { } ) ) ;
44 } ) ;
55
6- it ( "returns false if a property exists " , function ( ) {
6+ it ( "retorna false si existe una propiedad " , function ( ) {
77 assert . isFalse ( isEmpty ( {
88 anything : false
99 } ) ) ;
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
22
33---
44
5- # Check for emptiness
5+ # Verificar los vacíos
66
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 ` .
88
9- Should work like that :
9+ Debería funcionar así :
1010
1111``` js
1212let schedule = {};
1313
1414alert ( isEmpty (schedule) ); // true
1515
16- schedule[" 8:30" ] = " get up " ;
16+ schedule[" 8:30" ] = " Hora de levantarse " ;
1717
1818alert ( isEmpty (schedule) ); // false
1919```
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ importance: 5
22
33---
44
5- # Sum object properties
5+ # Suma de propiedades de un objeto
66
7- We have an object storing salaries of our team :
7+ Tenemos un objeto que almacena los salarios de nuestro equipo :
88
99``` js
1010let salaries = {
@@ -14,6 +14,6 @@ let salaries = {
1414}
1515```
1616
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 ` .
1818
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 11let menu = {
22 width : 200 ,
33 height : 300 ,
4- title : "My menu "
4+ title : "Mi menú "
55} ;
66
77
88function multiplyNumeric ( obj ) {
99
10- /* your code */
10+ /* tu código */
1111
1212}
1313
1414multiplyNumeric ( menu ) ;
1515
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 11describe ( "multiplyNumeric" , function ( ) {
2- it ( "multiplies all numeric properties by 2" , function ( ) {
2+ it ( "multiplicar todas las propiedades numéricas por 2" , function ( ) {
33 let menu = {
44 width : 200 ,
55 height : 300 ,
6- title : "My menu "
6+ title : "Mi menú "
77 } ;
88 let result = multiplyNumeric ( menu ) ;
99 assert . equal ( menu . width , 400 ) ;
1010 assert . equal ( menu . height , 600 ) ;
11- assert . equal ( menu . title , "My menu " ) ;
11+ assert . equal ( menu . title , "Mi menú " ) ;
1212 } ) ;
1313
14- it ( "returns nothing " , function ( ) {
14+ it ( "No devuelve nada " , function ( ) {
1515 assert . isUndefined ( multiplyNumeric ( { } ) ) ;
1616 } ) ;
1717
Original file line number Diff line number Diff line change @@ -2,32 +2,32 @@ importance: 3
22
33---
44
5- # Multiply numeric properties by 2
5+ # Multiplicar propiedades numéricas por 2
66
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 ` .
88
9- For instance :
9+ Por ejemplo :
1010
1111``` js
12- // before the call
12+ // Antes de la llamada
1313let menu = {
1414 width: 200 ,
1515 height: 300 ,
16- title: " My menu "
16+ title: " Mi menú "
1717};
1818
1919multiplyNumeric (menu);
2020
21- // after the call
21+ // Después de la llamada
2222menu = {
2323 width: 400 ,
2424 height: 600 ,
25- title: " My menu "
25+ title: " Mi menú "
2626};
2727```
2828
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 .
3030
31- P.S. Use ` typeof ` to check for a number here .
31+ P.D. Usa ` typeof ` para verificar si hay un número aquí .
3232
3333
You can’t perform that action at this time.
0 commit comments