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
The code works, but there's a potential performance problem in it.
26
+
El código funciona pero tiene un problema potencial de desempeño.
26
27
27
-
The method`result.includes(str)`internally walks the array `result`and compares each element against`str`to find the match.
28
+
El método`result.includes(str)`internamente recorre el array `result`y compara cada elemento con`str`para encontrar una coincidencia.
28
29
29
-
So if there are `100`elements in`result`and no one matches`str`, then it will walk the whole`result`and do exactly `100`comparisons. And if`result`is large, like `10000`, then there would be `10000`comparisons.
30
+
Por lo tanto, si hay `100`elementos en`result`y ninguno coincide con`str`, entonces habrá recorrido todo el array`result`y ejecutado `100`comparaciones. Y si`result`es tan grande como `10000`, entonces habrá `10000`comparaciones.
30
31
31
-
That's not a problem by itself, because JavaScript engines are very fast, so walk `10000`array is a matter of microseconds.
32
+
Esto no es un problema en sí mismo, porque los motores JavaScript son muy rápidos, por lo que recorrer `10000`elementos de un array solo le tomaría microsegundos.
32
33
33
-
But we do such test for each element of `arr`, in the `for` loop.
34
+
Pero ejecutamos dicha comprobación para cada elemento de `arr` en el loop `for`.
34
35
35
-
So if`arr.length`is`10000`we'll have something like `10000*10000` = 100 millions of comparisons. That's a lot.
36
+
Entonces si`arr.length`es`10000`vamos a tener algo como `10000*10000` = 100 millones de comparaciones. Esto es realmente mucho.
36
37
37
-
So the solution is only good for small arrays.
38
+
Por lo que la solución solo es buena para arrays pequeños.
38
39
39
-
Further in the chapter <info:map-set>we'll see how to optimize it.
40
+
Más adelante en el capítulo <info:map-set>vamos a ver como optimizarlo.
0 commit comments