Skip to content

Commit 12412d6

Browse files
authored
JSON methods, toJSON (#186)
* wip: json * json * json * json * json * json * json * json * json
1 parent a92a7b8 commit 12412d6

File tree

5 files changed

+170
-170
lines changed

5 files changed

+170
-170
lines changed

1-js/05-data-types/12-json/1-serialize-object/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```js
44
let user = {
5-
name: "John Smith",
5+
name: "Іван Іванов",
66
age: 35
77
};
88

1-js/05-data-types/12-json/1-serialize-object/task.md

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

33
---
44

5-
# Turn the object into JSON and back
5+
# Перетворіть об’єкт в JSON і назад
66

7-
Turn the `user` into JSON and then read it back into another variable.
7+
Перетворіть `user` в JSON, а потім перетворіть його назад в іншу змінну.
88

99
```js
1010
let user = {
11-
name: "John Smith",
11+
name: "Іван Іванов",
1212
age: 35
1313
};
1414
```

1-js/05-data-types/12-json/2-serialize-event-circular/solution.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ let room = {
55
};
66

77
let meetup = {
8-
title: "Conference",
9-
occupiedBy: [{name: "John"}, {name: "Alice"}],
8+
title: "Конференція",
9+
occupiedBy: [{name: "Іван"}, {name: "Аліса"}],
1010
place: room
1111
};
1212

@@ -19,12 +19,12 @@ alert( JSON.stringify(meetup, function replacer(key, value) {
1919

2020
/*
2121
{
22-
"title":"Conference",
23-
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
22+
"title":"Конференція",
23+
"occupiedBy":[{"name":"Іван"},{"name":"Аліса"}],
2424
"place":{"number":23}
2525
}
2626
*/
2727
```
2828

29-
Here we also need to test `key==""` to exclude the first call where it is normal that `value` is `meetup`.
29+
Тут нам також потрібно перевірити `key==""`, щоб виключити перший виклик, де значення `value` рівне `meetup`.
3030

1-js/05-data-types/12-json/2-serialize-event-circular/task.md

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

33
---
44

5-
# Exclude backreferences
5+
# Виключити зворотні посилання
66

7-
In simple cases of circular references, we can exclude an offending property from serialization by its name.
7+
У простих випадках циклічних посиланнь ми можемо виключити від серіалізації властивість, через яку воно виникло, за її ім’ям.
88

9-
But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
9+
Але іноді ми не можемо просто використовувати назву, оскільки вона може використовуватися як і у циклічних посиланнях, так і в нормальних властивостях. Таким чином, ми можемо перевірити властивість за її значенням.
1010

11-
Write `replacer` function to stringify everything, but remove properties that reference `meetup`:
11+
Напишіть функцію `replacer`, щоб серіалізувати все, але видалити властивості, які посилаються на `meetup`:
1212

1313
```js run
1414
let room = {
1515
number: 23
1616
};
1717

1818
let meetup = {
19-
title: "Conference",
20-
occupiedBy: [{name: "John"}, {name: "Alice"}],
19+
title: "Конференція",
20+
occupiedBy: [{name: "Іван"}, {name: "Аліса"}],
2121
place: room
2222
};
2323

2424
*!*
25-
// circular references
25+
// циклічне посилання
2626
room.occupiedBy = meetup;
2727
meetup.self = meetup;
2828
*/!*
2929

3030
alert( JSON.stringify(meetup, function replacer(key, value) {
31-
/* your code */
31+
/* ваш код */
3232
}));
3333

34-
/* result should be:
34+
/* результат повинен бути:
3535
{
36-
"title":"Conference",
37-
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
36+
"title":"Конференція",
37+
"occupiedBy":[{"name":"Іван"},{"name":"Аліса"}],
3838
"place":{"number":23}
3939
}
4040
*/

0 commit comments

Comments
 (0)