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

Map and Set translation#148

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
tarasyyyk merged 13 commits intojavascript-tutorial:masterfromRegnised:master
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
b63e9f7
Map and Set translation
Jul 22, 2021
e739584
Update translation
Jul 23, 2021
37bcae9
Fix word
RegnisedJul 23, 2021
4c8d232
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
915ffdb
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
5585083
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
44a0613
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
7b2db38
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
a03cc54
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 25, 2021
ee5e346
Update 1-js/05-data-types/07-map-set/article.md
RegnisedJul 26, 2021
9d95f57
Map and Set: spaces and other fixes
RegnisedJul 26, 2021
aa21873
Merge branch 'master' of github.com:Regnised/uk.javascript.info
RegnisedJul 26, 2021
1be3f05
Update 1-js/05-data-types/07-map-set/02-filter-anagrams/solution.md
tarasyyykJul 27, 2021
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,13 +1,13 @@
describe("unique", function() {
it("removes non-unique elements", function() {
it("видалити не унікальні елементи", function() {
let strings = ["Hare", "Krishna", "Hare", "Krishna",
"Krishna", "Krishna", "Hare", "Hare", ":-O"
];

assert.deepEqual(unique(strings), ["Hare", "Krishna", ":-O"]);
});

it("does not change the source array", function() {
it("не змінювати вихідний масив", function() {
let strings = ["Krishna", "Krishna", "Hare", "Hare"];
unique(strings);
assert.deepEqual(strings, ["Krishna", "Krishna", "Hare", "Hare"]);
Expand Down
14 changes: 7 additions & 7 deletions1-js/05-data-types/07-map-set/01-array-unique-map/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,17 +2,17 @@ importance: 5

---

#Filter unique array members
#Фільтрувати унікальні елементи масиву

Let `arr`be an array.
Нехай `arr`- це масив.

Create a function `unique(arr)` that should return an array with unique items of `arr`.
Потрібно створити функцію `unique(arr)`, яка повинна повертати масив унікальних елементів `arr`.

For instance:
Наприклад:

```js
function unique(arr) {
/*your code */
/*Твій код */
}

let values = ["Hare", "Krishna", "Hare", "Krishna",
Expand All@@ -22,6 +22,6 @@ let values = ["Hare", "Krishna", "Hare", "Krishna",
alert( unique(values) ); // Hare, Krishna, :-O
```

P.S.Here strings are used, but can be values of any type.
P.S.В прикладі ми використали рядки, але можуть бути значення будь-якого типу.

P.P.S.Use `Set`to store unique values.
P.P.S.Використайте `Set`для формування множини унікальних значень.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ function intersection(arr1, arr2) {
return arr1.filter(item => arr2.includes(item));
}

describe("aclean", function() {
describe("aclean", function() {

it("returns exactly 1word from each anagram set", function() {
it("повертає тільки 1слово для кожного набору анаграм", function() {
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];

let result = aclean(arr);
Expand All@@ -16,7 +16,7 @@ describe("aclean", function() {

});

it("is case-insensitive", function() {
it("не враховує регістр", function() {
let arr = ["era", "EAR"];
assert.equal(aclean(arr).length, 1);
});
Expand Down
24 changes: 12 additions & 12 deletions1-js/05-data-types/07-map-set/02-filter-anagrams/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
To find all anagrams, let's split every word to letters and sort them. When letter-sorted, all anagrams are same.
Щоб знайти всі анаграми, давайте розіб'ємо кожне слово на літери і відсортуємо їх, а потім об'єднаємо масив знову в рядок. Після цього всі анаграми будуть однакові.

For instance:
Наприклад:

```
nap, pan -> anp
Expand All@@ -9,14 +9,14 @@ cheaters, hectares, teachers -> aceehrst
...
```

We'll use the letter-sorted variants as map keys to store only one value per each key:
Ми будемо використовувати відсортовані рядки як ключі в колекції Map, для того щоб зіставити кожному ключу тільки одне значення:

```js run
function aclean(arr) {
let map = new Map();

for (let word of arr) {
//split the word by letters, sort them and join back
//розділіть слово на літери, відсортуйте їх та знову з'єднайте
*!*
let sorted = word.toLowerCase().split('').sort().join(''); // (*)
*/!*
Expand All@@ -31,9 +31,9 @@ let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];
alert( aclean(arr) );
```

Letter-sorting is done by the chain of calls in the line `(*)`.
Сортування літер здійснюється ланцюжком викликів одним рядком `(*)`.

For convenience let's split it into multiple lines:
Для зручності давайте розіб'ємо на декілька рядків:

```js
let sorted = word // PAN
Expand All@@ -43,21 +43,21 @@ let sorted = word // PAN
.join(''); // anp
```

Two different words `'PAN'`and `'nap'`receive the same letter-sorted form `'anp'`.
Два різних слова `'PAN'`і `'nap'`приймають ту ж саму форму після сортування букв - `'anp'`.

The next line put the word into the map:
Наступна лінія поміщає слово в об'єкт `Map`:

```js
map.set(sorted, word);
```

If we ever meet a word the same letter-sorted form again, then it would overwrite the previous value with the same key in the map. So we'll always have at maximum one word per letter-form.
Якщо ми коли-небудь ще зустрінемо слово в тій же відсортованої формі, тоді це слово перезапише значення з тим же ключем в об'єкті. Таким чином, декільком словами у нас буде завжди відповідати одна відсортована форма.

At the end`Array.from(map.values())`takes an iterable over map values (we don't need keys in the result) and returns an array of them.
Врешті-решт`Array.from(map.values())`приймає значення об'єкта-ітератора 'Map' (в цьому випадку нам не потрібні ключі) і повертає їх у вигляді масиву.

Here we could also use a plain object instead of the`Map`,because keys are strings.
Тут ми також можемо використовувати звичайний об'єкт замість`Map`,тому що ключі - це рядки.

That's how the solution can look:
Ось один з варіантів рішень задачі:

```js run demo
function aclean(arr) {
Expand Down
12 changes: 6 additions & 6 deletions1-js/05-data-types/07-map-set/02-filter-anagrams/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,27 +2,27 @@ importance: 4

---

#Filter anagrams
#Відфільтруйте анаграми

[Anagrams](https://en.wikipedia.org/wiki/Anagram)are words that have the same number of same letters, but in different order.
[Анаграми](https://en.wikipedia.org/wiki/Anagram)-- це слова, у яких ті ж букви в тій же кількості, але вони розташовуються в іншому порядку.

For instance:
Наприклад:

```
nap - pan
ear - are - era
cheaters - hectares - teachers
```

Write a function`aclean(arr)` that returns an array cleaned from anagrams.
Напишіть функцію`aclean(arr)`, яка повертає масив без анаграм.

For instance:
Наприклад:

```js
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];

alert( aclean(arr) ); // "nap,teachers,ear" or "PAN,cheaters,era"
```

From every anagram group should remain only one word, no matter which one.
З кожної групи анаграм має залишитися тільки одне слово, не має значення яке.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@

That's because`map.keys()`returns an iterable, but not an array.
Ми отримали помилку тому, що`map.keys()`повертає об'єкт-ітератор, а не масив.

We can convert it into an array using `Array.from`:
Ми можемо конвертувати його використовуючи `Array.from`:


```js run
Expand Down
10 changes: 5 additions & 5 deletions1-js/05-data-types/07-map-set/03-iterable-keys/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,11 @@ importance: 5

---

#Iterable keys
#Перебираємо ключі

We'd like to get an array of`map.keys()`in a variable and then apply array-specific methods to it, e.g. `.push`.
Ми хотіли б отримати масив ключів`map.keys()`в змінну і далі працювати з ними, наприклад, застосувати метод `.push`.

But that doesn't work:
Але так не спрацює:

```js run
let map = new Map();
Expand All@@ -16,9 +16,9 @@ map.set("name", "John");
let keys = map.keys();

*!*
//Error: keys.pushis not a function
//Помилка: keys.push-- це не функція
keys.push("more");
*/!*
```

Why? How can we fix the code to make`keys.push`work?
Чому? Що потрібно виправити в коді, щоб`keys.push`працював?
Loading

[8]ページ先頭

©2009-2025 Movatter.jp