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

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
CheerfulCherry merged 19 commits intojavascript-tutorial:masterfromCheerfulCherry:master
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
12b07a8
03-string>1-ucfirst
CheerfulCherryMay 29, 2022
b161b30
03-string>2-check-spam
CheerfulCherryMay 30, 2022
20587fa
03-string>03-truncate
CheerfulCherryMay 30, 2022
badc904
03-string>4-extract-currency
CheerfulCherryMay 30, 2022
f380c0b
string#quotes
CheerfulCherryJun 5, 2022
7e952df
string#special-characters
CheerfulCherryJun 5, 2022
82285a9
string#string-length
CheerfulCherryJun 12, 2022
adcfca6
string#accessing-characters
CheerfulCherryJun 12, 2022
6ae22e7
string#strings-are-immutable
CheerfulCherryJun 12, 2022
5100f5f
string#changing-the-case
CheerfulCherryJun 12, 2022
e2c28bf
string#searching-for-a-substring
CheerfulCherryJun 12, 2022
075ea56
string#getting-a-substring
CheerfulCherryJun 13, 2022
b12d778
string#comparing-strings
CheerfulCherryJun 13, 2022
5ed97bc
string#correct-comparisons
CheerfulCherryJun 17, 2022
8d6c4b8
string#surrogate-pairs
CheerfulCherryJun 20, 2022
2f21740
#diacritical-marks-and-normalization
CheerfulCherryJun 21, 2022
c35927c
string#summary
CheerfulCherryJun 21, 2022
66fa6e8
small fixes
CheerfulCherryJun 21, 2022
2281d2e
Update test.js
CheerfulCherryOct 15, 2022
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
6 changes: 3 additions & 3 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('Zmienia pierwszy znak na wielką literę', function() {
assert.strictEqual(ucFirst("john"), "John");
});

it("Doesn't die on an empty string", function() {
it("Nie wysypuje się na pustym łańcuchu", function() {
assert.strictEqual(ucFirst(""), "");
});
});
});
14 changes: 7 additions & 7 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, because strings inJavaScriptare immutable.
Nie możemy "zastąpić" pierwszego znaku, ponieważ łańcuchy znaków wJavaScriptsą niezmienne.

But we can make a new string based on the existing one, with the uppercased first character:
Możemy jednak stworzyć nowy łańcuch na podstawie istniejącego z pierwszym znakiem, jako wielką literą:

```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.
Jest jednak mały problem. Jeśli `str`jest pusty, to `str[0]`zwróci `undefined`,a`undefined`nie ma metody `toUpperCase()`, więc otrzymamy błąd.

There are two variants here:
Są dwa wyjścia:

1.Use `str.charAt(0)`,as it always returns a string (maybe empty).
2.Add a test for an empty string.
1.Użyj `str.charAt(0)`,ponieważ ta metoda zawsze zwraca łańcuch znaków (może być pusty).
2.Dodaj warunek na wypadek pustego łańcucha.

Here's the 2nd variant:
Oto druga opcja:

```js run demo
function ucFirst(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

---

#Uppercase the first character
#Zrób pierwszy znak wielką literą

Write a function`ucFirst(str)` that returns the string`str`with the uppercased first character, for instance:
Napisz funkcję`ucFirst(str)`, która zwraca ciąg`str`z pierwszym znakiem wielką literą. Na przykład:

```js
ucFirst("john") == "John";
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
describe("checkSpam", function() {
it('finds spam in"buy ViAgRA now"', function() {
it('uważa"buy ViAgRA now" za spam', function() {
assert.isTrue(checkSpam('buy ViAgRA now'));
});

it('finds spam in"free xxxxx"', function() {
it('uważa"free xxxxx" za spam', function() {
assert.isTrue(checkSpam('free xxxxx'));
});

it('no spam in"innocent rabbit"', function() {
it('nie uważa"innocent rabbit" za spam', function() {
assert.isFalse(checkSpam('innocent rabbit'));
});
});
2 changes: 1 addition & 1 deletion1-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:
Aby wyszukiwanie działało bez względu na wielkość liter, przekonwertujemy cały łańcuch na małe litery, a następnie sprawdzimy, czy zawiera szukany ciąg znaków:

```js run demo
function checkSpam(str) {
Expand Down
6 changes: 3 additions & 3 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,11 +2,11 @@ importance: 5

---

#Check for spam
#Sprawdzanie pod kątem spamu

Write a function`checkSpam(str)` that returns `true`if `str`contains 'viagra'or 'XXX',otherwise `false`.
Napisz funkcję`checkSpam(str)`, która zwraca `true`jeśli `str`zawiera 'viagra'lub 'XXX',w przeciwnym wypadku `false`.

The function must be case-insensitive:
Funkcja musi być niewrażliwa na wielkość liter:

```js
checkSpam('buy ViAgRA now') == true
Expand Down
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 long string to the given length (including the ellipsis)", function() {
it("obcina ciąg do podanej długości (łącznie z wielokropkiem)", function() {
assert.equal(
truncate("What I'd like to tell on this topic is:", 20),
"What I'd like to te…"
truncate("Oto, co chciałbym powiedzieć na ten temat:", 20),
"Oto, co chciałbym p…"
);
});

it("doesn't change short strings", function() {
it("nie zmienia krótkich łańcuchów", function() {
assert.equal(
truncate("Hi everyone!", 20),
"Hi everyone!"
truncate("Cześć wszystkim!", 20),
"Cześć wszystkim!"
);
});

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 needtocut it a little shorter, to give space for the ellipsis.
Zwracany ciąg nie może być dłuższy niż`maxlength`,więc jeśli go skrócimy,tomusimy usunąć o jeden znak mniej, aby zrobić miejsce na wielokropek.

Note that there is actually a single unicode character for an ellipsis. That's not three dots.
Należy pamiętać, że wielokropek to '…' – dokładnie jeden znak specjalny Unicode. To nie to samo, co '. . .' – trzy kropki.

```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
#Obcinanie tekstu

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`.
Utwórz funkcję`truncate(str, maxlength)`, która sprawdza długość łańcucha`str`i jeśli przekracza`maxlength`, zamienia koniec`str`na `…`,tak aby jego długość była równa `maxlength`.

The result of the function should be the truncated (if needed) string.
Wynik funkcji musi być tym samym ciągiem, jeśli obcięcie nie jest wymagane lub obciętym ciągiem, jeśli to konieczne.

For instance:
Na przykład:

```js
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
truncate("Oto, co chciałbym powiedzieć na ten temat:", 20) = "Oto, co chciałbym p…"

truncate("Hi everyone!", 20) = "Hi everyone!"
truncate("Cześć wszystkim!", 20) = "Cześć wszystkim!"
```
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("dla ciągu$120zwraca numer 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
#Wyciągnij liczbę

We have a cost in the form`"$120"`.That is: the dollar sign goes first, and then the number.
Mamy koszty zapisane w postaci ciągu`"$120"`.Oznacza to, że najpierw pojawia się znak dolara, a następnie liczba.

Create a function`extractCurrencyValue(str)`that would extract the numeric value from such string and return it.
Stwórz funkcję`extractCurrencyValue(str)`która wydobędzie wartość liczbową z takiego ciągu i ją zwróci.

The example:
Na przykład:

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

[8]ページ先頭

©2009-2025 Movatter.jp