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

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
otmon76 merged 1 commit intojavascript-tutorial:masterfromotmon76:1.5.3
Jun 3, 2025
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
@@ -1,5 +1,5 @@
functionucFirst(str) {
if (!str) returnstr;
functionvelkéPrvníPísmeno(řetězec) {
if (!řetězec) returnřetězec;

returnstr[0].toUpperCase() +str.slice(1);
returnřetězec[0].toUpperCase() +řetězec.slice(1);
}
10 changes: 5 additions & 5 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() {
assert.strictEqual(ucFirst("john"), "John");
describe("velkéPrvníPísmeno", function() {
it('První symbol převede na velké písmeno', function() {
assert.strictEqual(velkéPrvníPísmeno("jan"), "Jan");
});

it("Doesn't die on an empty string", function() {
assert.strictEqual(ucFirst(""), "");
it("Nespadne na prázdném řetězci", function() {
assert.strictEqual(velkéPrvníPísmeno(""), "");
});
});
18 changes: 9 additions & 9 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, because strings in JavaScript are immutable.
Nemůžeme „nahradit“ první znak, protože řetězce v JavaScriptu jsou neměnné.

But we can make a new string based on the existing one, with the uppercased first character:
Můžeme však vytvořit z existujícího řetězce nový, který bude mít první znak převedený na velké písmeno:

```js
letnewStr =str[0].toUpperCase() +str.slice(1);
letnovýŘetězec =řetězec[0].toUpperCase() +řetězec.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.
Je tady však malý problém. Jestliže `řetězec` je prázdný, pak `řetězec[0]`je `undefined`,a protože `undefined`nemá metodu`toUpperCase()`, dostaneme chybu.

The easiest way out istoadd atestfor an empty string, like this:
Nejjednodušší způsob, jaktovyřešit, je přidattestna prázdný řetězec, například takto:

```js run demo
functionucFirst(str) {
if (!str) returnstr;
functionvelkéPrvníPísmeno(řetězec) {
if (!řetězec) returnřetězec;

returnstr[0].toUpperCase() +str.slice(1);
returnřetězec[0].toUpperCase() +řetězec.slice(1);
}

alert(ucFirst("john") ); //John
alert(velkéPrvníPísmeno("jan") ); //Jan
```
6 changes: 3 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,11 @@ importance: 5

---

#Uppercase the first character
#Změňte první znak na velké písmeno

Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
Napište funkci `velkéPrvníPísmeno(řetězec)`, která vrátí `řetězec` upravený tak, že první znak bude převeden na velké písmeno, například:

```js
ucFirst("john") == "John";
velkéPrvníPísmeno("jan") == "Jan";
```

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
functioncheckSpam(str) {
letlowerStr =str.toLowerCase();
functionověřSpam(řetězec) {
letřetězecMalýmiPísmeny =řetězec.toLowerCase();

returnlowerStr.includes('viagra') ||lowerStr.includes('xxx');
returnřetězecMalýmiPísmeny.includes('viagra') ||řetězecMalýmiPísmeny.includes('xxx');
}
14 changes: 7 additions & 7 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'));
describe("ověřSpam", function() {
it('najde spamve "levná ViAgRAzde"', function() {
assert.isTrue(ověřSpam('levná ViAgRAzde'));
});

it('finds spamin "free xxxxx"', function() {
assert.isTrue(checkSpam('free xxxxx'));
it('najde spamve "zdarma xxxxx"', function() {
assert.isTrue(ověřSpam('zdarma xxxxx'));
});

it('no spamin "innocent rabbit"', function() {
assert.isFalse(checkSpam('innocent rabbit'));
it('není spamv "nevinný králíček"', function() {
assert.isFalse(ověřSpam('nevinný králíček'));
});
});
14 changes: 7 additions & 7 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,14 +1,14 @@
To make the search case-insensitive, let's bring the string to lower case and then search:
Aby hledání nerozlišovalo malá a velká písmena, převedeme řetězec na malá písmena a pak budeme hledat:

```js run demo
functioncheckSpam(str) {
letlowerStr =str.toLowerCase();
functionověřSpam(řetězec) {
letřetězecMalýmiPísmeny =řetězec.toLowerCase();

returnlowerStr.includes('viagra') ||lowerStr.includes('xxx');
returnřetězecMalýmiPísmeny.includes('viagra') ||řetězecMalýmiPísmeny.includes('xxx');
}

alert(checkSpam('buy ViAgRAnow') );
alert(checkSpam('free xxxxx') );
alert(checkSpam("innocent rabbit") );
alert(ověřSpam('levná ViAgRAzde') );
alert(ověřSpam('zdarma xxxxx') );
alert(ověřSpam("nevinný králíček") );
```

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
#Kontrola spamu

Write a function `checkSpam(str)` that returns `true` if `str` contains'viagra' or'XXX', otherwise `false`.
Napište funkci `ověřSpam(řetězec)`, která vrátí `true`, jestliže `řetězec` obsahuje `'viagra'` nebo `'XXX'`, jinak vrátí `false`.

The function must be case-insensitive:
Funkce nesmí rozlišovat malá a velká písmena:

```js
checkSpam('buy ViAgRAnow') == true
checkSpam('free xxxxx') == true
checkSpam("innocent rabbit") == false
ověřSpam('levná ViAgRAzde') == true
ověřSpam('zdarma xxxxx') == true
ověřSpam("nevinný králíček") == false
```

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
functiontruncate(str, maxlength) {
return (str.length >maxlength) ?
str.slice(0,maxlength - 1) + '…' :str;
functionzkrať(řetězec, maxDélka) {
return (řetězec.length >maxDélka) ?
řetězec.slice(0,maxDélka - 1) + '…' :řetězec;
}
14 changes: 7 additions & 7 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 long string to the given length (including the ellipsis)", function() {
describe("zkrať", function() {
it("zkrátí dlouhý řetězec na zadanou délku (včetně výpustky)", function() {
assert.equal(
truncate("What I'd like to tell on this topic is:", 20),
"What I'd like to te…"
truncate("To, co bych k tomuto tématu rád řekl, je:", 20),
"To, co bych k tomut…"
);
});

it("doesn't change short strings", function() {
it("nezmění krátké řetězce", function() {
assert.equal(
truncate("Hi everyone!", 20),
"Hi everyone!"
truncate("Ahoj všichni!", 20),
"Ahoj všichni!"
);
});

Expand Down
10 changes: 5 additions & 5 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,10 +1,10 @@
The maximal length must be `maxlength`,so we need to cut it a little shorter, to give space for the ellipsis.
Maximální délka musí být `maxDélka`,takže musíme odříznout řetězec kratší o jeden znak, abychom získali místo pro výpustku.

Note that there is actually a single Unicodecharacter for an ellipsis. That's not three dots.
Všimněte si, že pro výpustku existuje v Unicodejediný znak. Nejsou to tři tečky za sebou.

```js run demo
functiontruncate(str, maxlength) {
return (str.length >maxlength) ?
str.slice(0,maxlength - 1) + '…' :str;
functionzkrať(řetězec, maxDélka) {
return (řetězec.length >maxDélka) ?
řetězec.slice(0,maxDélka - 1) + '…' :řetězec;
}
```
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
#Zkrácení textu

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`.
Vytvořte funkci `zkrať(řetězec, maxDélka)`, která zkontroluje délku řetězce `řetězec`, a pokud překročí `maxDélka`, nahradí konec řetězce `řetězec` znakem tří teček (výpustkou) `"…"`,aby jeho délka byla přesně `maxDélka`.

The result of the function should be the truncated (if needed) string.
Výsledkem funkce by měl být zkrácený (je-li to nutné) řetězec.

For instance:
Například:

```js
truncate("What I'd like to tell on this topic is:", 20) == "What I'd like to te…"
zkrať("To, co bych k tomuto tématu rád řekl, je:", 20) == "To, co bych k tomut…"

truncate("Hi everyone!", 20) == "Hi everyone!"
zkrať("Ahoj všichni!", 20) == "Ahoj všichni!"
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
functionextractCurrencyValue(str) {
return +str.slice(1);
functionvyjmiČástku(řetězec) {
return +řetězec.slice(1);
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
describe("extractCurrencyValue", function() {
describe("vyjmiČástku", function() {

it("for the string$120returns the number 120", function() {
assert.strictEqual(extractCurrencyValue('$120'), 120);
it("pro řetězec$120vrátí číslo 120", function() {
assert.strictEqual(vyjmiČástku('$120'), 120);
});


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

---

#Extract the money
#Vyjmutí částky

We have a cost in the form`"$120"`.That is: the dollar sign goes first, and then the number.
Máme cenu ve tvaru`"$120"`.Tedy: jako první je znak dolaru, pak číslo.

Create a function `extractCurrencyValue(str)` that would extract the numeric value from such string and return it.
Vytvořte funkci `vyjmiČástku(řetězec)`, která z takového řetězce vytáhne číselnou hodnotu a vrátí ji.

The example:
Příklad:

```js
alert(extractCurrencyValue('$120') === 120 ); // true
alert(vyjmiČástku('$120') === 120 ); // true
```

Loading

[8]ページ先頭

©2009-2025 Movatter.jp