Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Strings#126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
joaquinelio merged 9 commits intojavascript-tutorial:masterfromferueda:master
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,4 +2,4 @@ function ucFirst(str) {
if (!str) return str;

return str[0].toUpperCase() + str.slice(1);
}
}
15 changes: 7 additions & 8 deletions1-js/05-data-types/03-string/1-ucfirst/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
We can't "replace" the first character, becausestringsin JavaScriptare immutable.
No podemos "reemplazar" el primer carácter, debido a que losstringsen JavaScriptson inmutables.

But we can make a newstringbased on the existing one, with the uppercased first character:
Pero podemos hacer un nuevostringbasado en el existente, con el primer carácter en mayúsculas:

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

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.
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.

There are two variants here:
Existen dos variantes:

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

Here's the 2nd variant:
Aquí está la segunda variante:

```js run demo
function ucFirst(str) {
Expand All@@ -24,4 +24,3 @@ function ucFirst(str) {

alert( ucFirst("john") ); // John
```

5 changes: 2 additions & 3 deletions1-js/05-data-types/03-string/1-ucfirst/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,10 @@ importance: 5

---

#Uppercase the first character
#Hacer mayúscula el primer caracter

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

```js
ucFirst("john") == "John";
```

8 changes: 4 additions & 4 deletions1-js/05-data-types/03-string/2-check-spam/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
Para que la búsqueda no distinga entre mayúsculas y minúsculas, llevemos el string a minúsculas y luego busquemos:

```js run demo
function checkSpam(str) {
Expand All@@ -7,8 +7,8 @@ function checkSpam(str) {
return lowerStr.includes('viagra') || lowerStr.includes('xxx');
}

alert( checkSpam('buy ViAgRAnow') );
alert( checkSpam('freexxxxx') );
alert( checkSpam("innocent rabbit") );
alert( checkSpam('compra ViAgRAahora') );
alert( checkSpam('xxxxx gratis') );
alert( checkSpam("coneja inocente") );
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No entiendo el cambio solicitado aquí.

spideep reacted with thumbs up emoji
```

12 changes: 6 additions & 6 deletions1-js/05-data-types/03-string/2-check-spam/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,15 @@ importance: 5

---

#Check for spam
#Buscar spam

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

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

```js
checkSpam('buy ViAgRAnow') == true
checkSpam('freexxxxx') == true
checkSpam("innocent rabbit") == false
checkSpam('compra ViAgRAahora') == true
checkSpam('xxxxx gratis') == true
checkSpam("coneja inocente") == false
```

4 changes: 2 additions & 2 deletions1-js/05-data-types/03-string/3-truncate/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
La longitud máxima debe ser 'maxlength', por lo que debemos acortarla un poco para dar espacio a los puntos suspensivos.

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

```js run demo
function truncate(str, maxlength) {
Expand Down
12 changes: 6 additions & 6 deletions1-js/05-data-types/03-string/3-truncate/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,16 +2,16 @@ importance: 5

---

#Truncate the text
#Truncar el texto

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`.
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`.

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

For instance:
Por ejemplo:

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

truncate("Hi everyone!", 20) = "Hi everyone!"
truncate("Hola a todos!", 20) = "Hola a todos!"
```
8 changes: 4 additions & 4 deletions1-js/05-data-types/03-string/4-extract-currency/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 4

---

#Extract the money
#Extraer el dinero

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

Create a function `extractCurrencyValue(str)`that would extract the numeric value from suchstringand return it.
Crea una función `extractCurrencyValue(str)`que extraiga el valor numérico de dichostringy lo devuelva.

The example:
Por ejemplo:

```js
alert( extractCurrencyValue('$120') === 120 ); // true
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp