You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//now readMessages has 1 element (technically memory may be cleaned later)
25
+
//ahora readMessages tiene 1 elemento (técnicamente la memoria puede limpiarse más tarde)
26
26
```
27
27
28
-
The `WeakSet` allows to store a set of messages and easily check for the existance of a message in it.
28
+
El `WeakEst` permite almacenar un conjunto de mensajes y verificar fácilmente la existencia de un mensaje en él.
29
29
30
-
It cleans up itself automatically. The tradeoff is that we can't iterate over it, can't get "all read messages" from it directly. But we can do it by iterating over all messages and filtering those that are in the set.
30
+
Se limpia automáticamente. La desventaja es que no podemos iterar sobre él, no podemos obtener "todos los mensajes leídos" directamente. Pero podemos hacerlo iterando sobre todos los mensajes y filtrando los que están en el conjunto.
31
31
32
-
Another, different solution could be to add a property like `message.isRead=true`to a message after it's read. As messages objects are managed by another code, that's generally discouraged, but we can use a symbolic property to avoid conflicts.
32
+
Otra solución diferente podría ser agregar una propiedad como `message.isRead = true`a un mensaje después de leerlo. Como los objetos de mensajes son administrados por otro código, generalmente se desaconseja, pero podemos usar una propiedad simbólica para evitar conflictos.
33
33
34
-
Like this:
34
+
Como esto:
35
35
```js
36
-
//the symbolic property is only known to our code
36
+
//la propiedad simbólica solo es conocida por nuestro código
37
37
let isRead =Symbol("isRead");
38
38
messages[0][isRead] =true;
39
39
```
40
40
41
-
Now third-party code probably won't see our extra property.
41
+
Ahora el código de terceros probablemente no verá nuestra propiedad adicional.
42
42
43
-
Although symbols allow to lower the probability of problems, using`WeakSet`is better from the architectural point of view.
43
+
Aunque los símbolos permiten reducir la probabilidad de problemas, usar`WeakSet`es mejor desde el punto de vista arquitectónico.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/08-weakmap-weakset/01-recipients-read/task.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Store "unread" flags
5
+
# Almacenar banderas "no leídas"
6
6
7
-
There's an array of messages:
7
+
Hay un array de mensajes:
8
8
9
9
```js
10
10
let messages = [
@@ -14,10 +14,10 @@ let messages = [
14
14
];
15
15
```
16
16
17
-
Your code can access it, but the messages are managed by someone else's code. New messages are added, old ones are removed regularly by that code, and you don't know the exact moments when it happens.
17
+
Su código puede acceder a él, pero los mensajes son administrados por el código de otra persona. Se agregan mensajes nuevos, los códigos viejos se eliminan regularmente con ese código, y usted no sabe los momentos exactos en que sucede.
18
18
19
-
Now, which data structure could you use to store information about whether the message "has been read"? The structure must be well-suited to give the answer "was it read?" for the given message object.
19
+
Ahora, ¿qué estructura de datos podría usar para almacenar información sobre si el mensaje "ha sido leído"? La estructura debe ser adecuada para dar la respuesta "¿se leyó?" para el objeto del mensaje dado.
20
20
21
-
P.S. When a message is removed from`messages`, it should disappear from your structure as well.
21
+
P.D Cuando un mensaje se elimina de`messages`, también debería desaparecer de su estructura.
22
22
23
-
P.P.S. We shouldn't modify message objects, add our properties to them. As they are managed by someone else's code, that may lead to bad consequences.
23
+
P.P.D. No debemos modificar los objetos del mensaje, o agregarles nuestras propiedades. Como son administrados por el código de otra persona, eso puede generarnos resultados no deseados.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/08-weakmap-weakset/02-recipients-when-read/task.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Store read dates
5
+
# Almacenar fechas de lectura
6
6
7
-
There's an array of messages as in the [previous task](info:task/recipients-read). The situation is similar.
7
+
Hay un array semejante al de la actividad anterior [previous task](info:task/recipients-read). La sitación es similar:
8
8
9
9
```js
10
10
let messages = [
@@ -14,8 +14,8 @@ let messages = [
14
14
];
15
15
```
16
16
17
-
The question now is: which data structure you'd suggest to store the information: "when the message was read?".
17
+
La pregunta ahora es: ¿qué estructura de datos es la adecuada para almacenar la información: "cuando se leyó el mensaje?".
18
18
19
-
In the previous task we only needed to store the "yes/no" fact. Now we need to store the date, and it should only remain in memory until the message is garbage collected.
19
+
En la tarea anterior solo necesitábamos almacenar el hecho de "sí / no". Ahora necesitamos almacenar la fecha, y solo debe permanecer en la memoria hasta que el mensaje sea recolectado como basura.
20
20
21
-
P.S. Dates can be stored as objects of built-in `Date` class, that we'll cover later.
21
+
P.D Las fechas se pueden almacenar como objetos de la clase incorporada `Date`, que cubriremos más adelante.
0 commit comments