Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 22, 2022
Merged
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
6 changes: 3 additions & 3 deletions 1-js/05-data-types/03-string/1-ucfirst/_js.view/test.js
Original file line number Diff line number Diff 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 deletions 1-js/05-data-types/03-string/1-ucfirst/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
We can't "replace" the first character, because strings in JavaScript are immutable.
Nie możemy "zastąpić" pierwszego znaku, ponieważ łańcuchy znaków w JavaScript są 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 deletions 1-js/05-data-types/03-string/1-ucfirst/task.md
Original file line number Diff line number Diff 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
6 changes: 3 additions & 3 deletions 1-js/05-data-types/03-string/2-check-spam/_js.view/test.js
Original file line number Diff line number Diff 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 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:
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 deletions 1-js/05-data-types/03-string/2-check-spam/task.md
Original file line number Diff line number Diff 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 deletions 1-js/05-data-types/03-string/3-truncate/_js.view/test.js
Original file line number Diff line number Diff 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 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.
Zwracany ciąg nie może być dłuższy niż `maxlength`, więc jeśli go skrócimy, to musimy 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 deletions 1-js/05-data-types/03-string/3-truncate/task.md
Original file line number Diff line number Diff 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!"
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("extractCurrencyValue", function() {

it("for the string $120 returns the number 120", function() {
it("dla ciągu $120 zwraca numer 120", function() {
assert.strictEqual(extractCurrencyValue('$120'), 120);
});

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