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#197

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

Closed
odsantos wants to merge6 commits intojavascript-tutorial:masterfromodsantos:update-strings
Closed
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
4 changes: 2 additions & 2 deletions1-js/05-data-types/03-string/1-ucfirst/_js.view/test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
describe("ucFirst", function() {
it('Uppercases the first symbol', function() {
it('Transforma o primeiro símbolo em maiúsculas', function() {
assert.strictEqual(ucFirst("john"), "John");
});

it("Doesn't die on an emptystring", function() {
it("Não aborta numastring vazia", function() {
assert.strictEqual(ucFirst(""), "");
});
});
16 changes: 8 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,21 +1,21 @@
We can't "replace" the first character, becausestrings in JavaScriptare immutable.
Não podemos "substituir" o primeiro caractere, porque *strings* em JavaScriptsão imutáveis.

But we can make a newstring based on the existing one, with the uppercased first character:
Mas podemos criar uma nova *string* com base na existente, com o primeiro caractere em maiúsculas:

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

There's a small problem though. If `str`is empty, then `str[0]`isundefined, so we'll get an error.
Contudo, há um pequeno problema. Se `str`estiver vazia, então `str[0]`será `undefined`, e como `undefined` não possui o método `toUpperCase()`, recebemos um erro.

There are two variants here:
Existem aqui duas variantes:

1. Use `str.charAt(0)`,as it always returns astring (maybe empty).
2.Add a test for an emptystring.
1. Use `str.charAt(0)`,porque sempre retorna uma *string* (ainda que vazia).
2.Adicione um teste por uma *string* vazia.

Here's the 2nd variant:
Aqui está a segunda variante:

```js run
```js run demo
function ucFirst(str) {
if (!str) return str;

Expand Down
4 changes: 2 additions & 2 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,9 +2,9 @@ importance: 5

---

#Uppercast the first character
#Transforme o primeiro caractere em maiúsculas

Write a function `ucFirst(str)`that returns thestring `str`with the uppercased first character, for instance:
Escreva uma função `ucFirst(str)`que retorne a *string* `str`com o primeiro caractere em maiúsculas, por exemplo:

```js
ucFirst("john") == "John";
Expand Down
12 changes: 6 additions & 6 deletions1-js/05-data-types/03-string/2-check-spam/_js.view/test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
describe("checkSpam", function() {
it('finds spamin "buy ViAgRAnow"', function() {
assert.isTrue(checkSpam('buy ViAgRAnow'));
it('encontra spamem "compre ViAgRAagora"', function() {
assert.isTrue(checkSpam('compre ViAgRAagora'));
});

it('finds spamin "freexxxxx"', function() {
assert.isTrue(checkSpam('freexxxxx'));
it('encontra spamem "xxxxx grátis"', function() {
assert.isTrue(checkSpam('xxxxx grátis'));
});

it('no spamin "innocent rabbit"', function() {
assert.isFalse(checkSpam('innocent rabbit'));
it('nenhum spamem "coelhinha inocente"', function() {
assert.isFalse(checkSpam('coelhinha inocente'));
});
});
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 searchcase-insensitive, let's bring thestring to lower case and then search:
Para fazer a pesquisa insensível ao caso (*case-insensitive*), vamos transformar a *string* em minúsculas e a seguir pesquisar:

```js run
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('compre ViAgRAagora') );
alert( checkSpam('xxxxx grátis') );
alert( checkSpam("coelhinha inocente") );
```

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
#Procure por spam

Write a function `checkSpam(str)`that returns `true`if `str`contains 'viagra'or 'XXX',otherwise`false.
Escreva uma função `checkSpam(str)`que retorne `true`se `str`contiver 'viagra'ou 'XXX',e em caso contrário retorne`false`.

The function must becase-insensitive:
A função deve ser insensível ao caso (*case-insensitive* - não sensível a maiúsculas/minúsculas):

```js
checkSpam('buy ViAgRAnow') == true
checkSpam('freexxxxx') == true
checkSpam("innocent rabbit") == false
checkSpam('compre ViAgRAagora') == true
checkSpam('xxxxx grátis') == true
checkSpam("coelhinha inocente") == false
```

12 changes: 6 additions & 6 deletions1-js/05-data-types/03-string/3-truncate/_js.view/test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
describe("truncate", function() {
it("truncate the longstringto the given length (including the ellipsis)", function() {
it("trunque astringlonga para o comprimento dado (incluindo as reticências)", function() {
assert.equal(
truncate("What I'd like to tell on this topic is:", 20),
"What I'd like to te…"
truncate("O que eu gostaria de dizer neste tópico é:", 20),
"O que eu gostaria d…"
);
});

it("doesn't change shortstrings", function() {
it("não alterastrings curtas", function() {
assert.equal(
truncate("Hi everyone!", 20),
"Hi everyone!"
truncate("Olá a todos!", 20),
"Olá a todos!"
);
});

Expand Down
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.
O comprimento máximo deve ser `maxlength`,portanto precisamos de a cortar um pouco antes, para dar espaço às reticências.

Notethat there is actually a single Unicode character for an ellipsis. That's not three dots.
Noteque realmente existe um caractere *unicode* único para as reticências. Não são três pontos.

```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
#Trunque o 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`.
Crie uma função `truncate(str, maxlength)`que verifique o comprimento de`str`e, se exceder a `maxlength` --substitua o final de `str`pelo caractere reticências`"…"`,afim de tornar o seu comprimento igual a `maxlength`.

The result of the function should be the truncated (if needed) string.
O resultado da função deverá ser a *string* truncada (se necessário).

For instance:
Por exemplo:

```js
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
truncate("O que eu gostaria de dizer neste tópico é:", 20) = "O que eu gostaria d…"

truncate("Hi everyone!", 20) = "Hi everyone!"
truncate("Olá a todos!", 20) = "Olá a todos!"
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
describe("extractCurrencyValue", function() {

it("for the string $120returns the number 120", function() {
it("para a string $120retorne o número 120", function() {
assert.strictEqual(extractCurrencyValue('$120'), 120);
});

Expand Down
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
#Extraia o valor monetário

We have a cost in the form`"$120"`.That is: the dollar sign goes first, and then the number.
Temos um custo na forma`"$120"`.Isto é: o sinal de dólar vem primeiro, e a seguir o número.

Create a function `extractCurrencyValue(str)`that would extract the numeric value from suchstring and return it.
Crie uma função `extractCurrencyValue(str)`que faça a extração do valor numérico dessa *string* e o retorne.

The example:
O exemplo:

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

[8]ページ先頭

©2009-2025 Movatter.jp