Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/1-ucfirst/solution.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
We can't "replace" the first character, because strings in JavaScript are immutable.
Não podemos "substituir" o primeiro caractere, pois strings em JavaScript são imutáveis.

But we can make a new string based on the existing one, with the uppercased first character:
Mas podemos fazer uma nova string baseando-se na existente, com o primeiro caractere em maiúsculo:

```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.
Entretanto, tem um pequeno problema. Se `str` está vazio, então `str[0]` é `undefined`, e como `undefined` não possui o método `toUpperCase()` teremos um erro.

The easiest way out is to add a test for an empty string, like this:
A maneira mais fácil de contornar é adicionar um teste para string vazia, algo assim:

```js run demo
function ucFirst(str) {
Expand Down
6 changes: 3 additions & 3 deletions 1-js/05-data-types/03-string/1-ucfirst/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
importance: 5
importância: 5

---

# Uppercase the first character
# Transforme o primeiro caractere em maiúsculo

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

```js
ucFirst("john") == "John";
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/03-string/2-check-spam/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
Para fazer a procura insensível a maiúsculas e minúsculas vamos transformar a string em minúsculas e então procurar:

```js run demo
function checkSpam(str) {
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/2-check-spam/task.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 5
importânica: 5

---

# Check for spam
# Checagem de spam

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

The function must be case-insensitive:
A função deve ser insensível a maiúsculas e minúsculas:

```js
checkSpam('buy ViAgRA now') == true
Expand Down
4 changes: 2 additions & 2 deletions 1-js/05-data-types/03-string/3-truncate/solution.md
Original file line number Diff line number Diff 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 tamanho máximo deve ser `maxlength`, então precisamos cortar a string um pouco para dar espaço à reticências.

Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
Note que há apenas um único caractere Unicode para reticências. Não são três pontos.

```js run demo
function truncate(str, maxlength) {
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/03-string/3-truncate/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
importance: 5
importância: 5

---

# Truncate the text
# Cortar 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 checa se o tamanho do `str` e, se exceder `maxlength` -- substitua o fim de `str` com o caractere de reticências `"…"`, para fazer seu tamanho igual ao `maxlength`.

The result of the function should be the truncated (if needed) string.
O resultado da função deve ser a string cortada(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…"
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/4-extract-currency/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 4

---

# Extract the money
# Extraia o dinheiro

We have a cost in the form `"$120"`. That is: the dollar sign goes first, and then the number.
Temos um custo no formato `"$120"`.Isso é: o cifrão aparece primeiro e depois o número.

Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
Crie uma função `extractCurrencyValue(str)` que extraia o valor numérico da string e o retorne.

The example:
O exemplo:

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