Skip to content

Commit a92f1be

Browse files
authored
Strings (#230)
1 parent 4e50111 commit a92f1be

File tree

12 files changed

+316
-316
lines changed

12 files changed

+316
-316
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
describe("ucFirst", function() {
2-
it('Uppercases the first symbol', function() {
2+
it('Перетворює перший символ у верхній регістр', function() {
33
assert.strictEqual(ucFirst("john"), "John");
44
});
55

6-
it("Doesn't die on an empty string", function() {
6+
it('Не вмирає на порожніх рядках', function() {
77
assert.strictEqual(ucFirst(""), "");
88
});
9-
});
9+
});
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
We can't "replace" the first character, because strings in JavaScript are immutable.
1+
Ми не можемо "замінити" перший символ, оскільки рядки в JavaScript незмінні.
22

3-
But we can make a new string based on the existing one, with the uppercased first character:
3+
Але ми можемо створити новий рядок на основі існуючого, з першим символом у верхньому регістрі:
44

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

9-
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.
9+
Але є невелика проблема. Якщо `str` порожній рядок, то `str[0]` буде `undefined`, а оскільки `undefined` не має методу `toUpperCase()`, ми отримаємо помилку.
1010

11-
There are two variants here:
11+
Тут є два варіанти:
1212

13-
1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
14-
2. Add a test for an empty string.
13+
1. Використати `str.charAt(0)`, оскільки він завжди повертає рядок (навіть для порожнього рядка).
14+
2. Додати перевірку на порожній рядок.
1515

16-
Here's the 2nd variant:
16+
Ось 2-й варіант:
1717

1818
```js run demo
1919
function ucFirst(str) {
@@ -22,6 +22,6 @@ function ucFirst(str) {
2222
return str[0].toUpperCase() + str.slice(1);
2323
}
2424

25-
alert( ucFirst("john") ); // John
25+
alert( ucFirst("василь") ); // Василь
2626
```
2727

1-js/05-data-types/03-string/1-ucfirst/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Uppercase the first character
5+
# Переведіть перший символ у верхній регістр
66

7-
Write a function `ucFirst(str)` that returns the string `str` with the uppercased first character, for instance:
7+
Напишіть функцію `ucFirst(str)`, яка повертає рядок `str` з першим символом у верхньому регістрі, наприклад:
88

99
```js
10-
ucFirst("john") == "John";
10+
ucFirst("василь") == "Василь";
1111
```
1212

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
describe("checkSpam", function() {
2-
it('finds spam in "buy ViAgRA now"', function() {
2+
it('знаходить спам у "buy ViAgRA now"', function() {
33
assert.isTrue(checkSpam('buy ViAgRA now'));
44
});
55

6-
it('finds spam in "free xxxxx"', function() {
6+
it('знаходить спам у "free xxxxx"', function() {
77
assert.isTrue(checkSpam('free xxxxx'));
88
});
99

10-
it('no spam in "innocent rabbit"', function() {
10+
it('не знаходить спам у "innocent rabbit"', function() {
1111
assert.isFalse(checkSpam('innocent rabbit'));
1212
});
13-
});
13+
});

1-js/05-data-types/03-string/2-check-spam/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To make the search case-insensitive, let's bring the string to lower case and then search:
1+
Щоб зробити пошук нечутливим до регістру, давайте переведемо рядок у нижній регістр, а потім здійснимо пошук:
22

33
```js run demo
44
function checkSpam(str) {

1-js/05-data-types/03-string/2-check-spam/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Check for spam
5+
# Перевірка на спам
66

7-
Write a function `checkSpam(str)` that returns `true` if `str` contains 'viagra' or 'XXX', otherwise `false`.
7+
Напишіть функцію `checkSpam(str)`, яка повертає `true`, якщо `str` містить 'viagra' or 'XXX', інакше `false`.
88

9-
The function must be case-insensitive:
9+
Функція має бути нечутливою до регістру:
1010

1111
```js
1212
checkSpam('buy ViAgRA now') == true

1-js/05-data-types/03-string/3-truncate/_js.view/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
describe("truncate", function() {
2-
it("truncate the long string to the given length (including the ellipsis)", function() {
2+
it("урізає довгий рядок до заданої довжини (включаючи три крапки)", function() {
33
assert.equal(
4-
truncate("What I'd like to tell on this topic is:", 20),
5-
"What I'd like to te…"
4+
truncate("Що я хотів би розповісти на цю тему:", 20),
5+
"Що я хотів би розпо…"
66
);
77
});
88

9-
it("doesn't change short strings", function() {
9+
it("не змінює короткі рядки", function() {
1010
assert.equal(
11-
truncate("Hi everyone!", 20),
12-
"Hi everyone!"
11+
truncate("Всім привіт!", 20),
12+
"Всім привіт!"
1313
);
1414
});
1515

1-js/05-data-types/03-string/3-truncate/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
1+
Максимальна довжина має бути `maxlength`, тому нам потрібно її трохи обрізати, щоб дати місце для символу трьох крапок.
22

3-
Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
3+
Зауважте, що насправді існує один юнікодний символ для "трьох крапок". Це не три послідовні крапки.
44

55
```js run demo
66
function truncate(str, maxlength) {

1-js/05-data-types/03-string/3-truncate/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ importance: 5
22

33
---
44

5-
# Truncate the text
5+
# Урізання тексту
66

7-
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`.
7+
Створіть функцію `truncate(str, maxlength)`, яка перевіряє довжину `str` і, якщо вона перевищує `maxlength` -- замінює кінець `str` символом трьох крапок `"…"`, щоб його довжина була рівною `maxlength`.
88

9-
The result of the function should be the truncated (if needed) string.
9+
Результатом функції повинен бути урізаний (якщо потребується) рядок.
1010

11-
For instance:
11+
Наприклад:
1212

1313
```js
14-
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te"
14+
truncate("Що я хотів би розповісти на цю тему:", 20) = "Що я хотів би розпо"
1515

16-
truncate("Hi everyone!", 20) = "Hi everyone!"
16+
truncate("Всім привіт!", 20) = "Всім привіт!"
1717
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
describe("extractCurrencyValue", function() {
22

3-
it("for the string $120 returns the number 120", function() {
3+
it("для рядка $120 повертає число 120", function() {
44
assert.strictEqual(extractCurrencyValue('$120'), 120);
55
});
66

77

8-
});
8+
});

0 commit comments

Comments
 (0)