Skip to content

Commit fb3b99c

Browse files
authored
Merge pull request #126 from ferueda/master
Strings
2 parents 284d4a0 + ed4d11c commit fb3b99c

File tree

9 files changed

+317
-319
lines changed

9 files changed

+317
-319
lines changed

1-js/05-data-types/03-string/1-ucfirst/_js.view/solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ function ucFirst(str) {
22
if (!str) return str;
33

44
return str[0].toUpperCase() + str.slice(1);
5-
}
5+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
We can't "replace" the first character, because strings in JavaScript are immutable.
1+
No podemos "reemplazar" el primer carácter, debido a que los strings en JavaScript son inmutables.
22

3-
But we can make a new string based on the existing one, with the uppercased first character:
3+
Pero podemos hacer un nuevo string basado en el existente, con el primer carácter en mayúsculas:
44

55
```js
66
let newStr = str[0].toUpperCase() + str.slice(1);
77
```
88

9-
There's a small problem though. If `str` is empty, then `str[0]` is `undefined`, and as `undefined` doesn't have the `toUpperCase()` method, we'll get an error.
9+
Sin embargo, hay un pequeño problema. Si `str` está vacío, entonces `str[0]` es `undefined`, y como `undefined` no tiene el método `toUpperCase()`, obtendremos un error.
1010

11-
There are two variants here:
11+
Existen dos variantes:
1212

13-
1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
14-
2. Add a test for an empty string.
13+
1. Usar `str.charAt(0)`, ya que siempre devuelve una cadena (tal vez vacía).
14+
2. Agregar una prueba para un string vacío.
1515

16-
Here's the 2nd variant:
16+
Aquí está la segunda variante:
1717

1818
```js run demo
1919
function ucFirst(str) {
@@ -24,4 +24,3 @@ function ucFirst(str) {
2424

2525
alert( ucFirst("john") ); // John
2626
```
27-

1-js/05-data-types/03-string/1-ucfirst/task.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ importance: 5
22

33
---
44

5-
# Uppercase the first character
5+
# Hacer mayúscula el primer caracter
66

7-
Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
7+
Escribe una función `ucFirst(str)` que devuelva el string `str` con el primer carácter en mayúscula, por ejemplo:
88

99
```js
1010
ucFirst("john") == "John";
1111
```
12-
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To make the search case-insensitive, let's bring the string to lower case and then search:
1+
Para que la búsqueda no distinga entre mayúsculas y minúsculas, llevemos el string a minúsculas y luego busquemos:
22

33
```js run demo
44
function checkSpam(str) {
@@ -7,8 +7,8 @@ function checkSpam(str) {
77
return lowerStr.includes('viagra') || lowerStr.includes('xxx');
88
}
99

10-
alert( checkSpam('buy ViAgRA now') );
11-
alert( checkSpam('free xxxxx') );
12-
alert( checkSpam("innocent rabbit") );
10+
alert( checkSpam('compra ViAgRA ahora') );
11+
alert( checkSpam('xxxxx gratis') );
12+
alert( checkSpam("coneja inocente") );
1313
```
1414

1-js/05-data-types/03-string/2-check-spam/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ importance: 5
22

33
---
44

5-
# Check for spam
5+
# Buscar spam
66

7-
Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
7+
Escribe una función `checkSpam(str)` que devuelva `true` si `str` contiene 'viagra' o 'XXX', de lo contrario `false`.
88

9-
The function must be case-insensitive:
9+
La función debe ser insensible a mayúsculas y minúsculas:
1010

1111
```js
12-
checkSpam('buy ViAgRA now') == true
13-
checkSpam('free xxxxx') == true
14-
checkSpam("innocent rabbit") == false
12+
checkSpam('compra ViAgRA ahora') == true
13+
checkSpam('xxxxx gratis') == true
14+
checkSpam("coneja inocente") == false
1515
```
1616

1-js/05-data-types/03-string/3-truncate/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
1+
La longitud máxima debe ser 'maxlength', por lo que debemos acortarla un poco para dar espacio a los puntos suspensivos.
22

3-
Note that there is actually a single unicode character for an ellipsis. That's not three dots.
3+
Tener en cuenta que en realidad hay un único carácter unicode para puntos suspensivos. Eso no son tres puntos.
44

55
```js run demo
66
function truncate(str, maxlength) {

1-js/05-data-types/03-string/3-truncate/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ importance: 5
22

33
---
44

5-
# Truncate the text
5+
# Truncar el texto
66

7-
Create a function `truncate(str, maxlength)` that checks the length of the `str` and, if it exceeds `maxlength` -- replaces the end of `str` with the ellipsis character `"…"`, to make its length equal to `maxlength`.
7+
Crea una función `truncate(str, maxlength)` que verifique la longitud de `str` y, si excede `maxlength` - reemplaza el final de `str` con el carácter de puntos suspensivos `"…"`, para hacer su longitud igual a `maxlength`.
88

9-
The result of the function should be the truncated (if needed) string.
9+
El resultado de la función debe ser la cadena truncada (si es necesario).
1010

11-
For instance:
11+
Por ejemplo:
1212

1313
```js
14-
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te"
14+
truncate("Lo que me gustaría contar sobre este tema es:", 20) = "Lo que me gustaría c"
1515

16-
truncate("Hi everyone!", 20) = "Hi everyone!"
16+
truncate("Hola a todos!", 20) = "Hola a todos!"
1717
```

1-js/05-data-types/03-string/4-extract-currency/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 4
22

33
---
44

5-
# Extract the money
5+
# Extraer el dinero
66

7-
We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
7+
Tenemos un costo en forma de "$120". Es decir: el signo de dólar va primero y luego el número.
88

9-
Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
9+
Crea una función `extractCurrencyValue(str)` que extraiga el valor numérico de dicho string y lo devuelva.
1010

11-
The example:
11+
Por ejemplo:
1212

1313
```js
1414
alert( extractCurrencyValue('$120') === 120 ); // true

0 commit comments

Comments
 (0)