-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
98 lines (89 loc) · 3.67 KB
/
main.js
File metadata and controls
98 lines (89 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* EASY
Алгоритмы !
TASK 0
Вам дано предложение, верните массив из слов,
которые длинее чем средняя длина всех слов.
Слова разделены пробелами, если в предложении запятые,они должны быть пропущены
solution(["This is a sample string"]) expected ["This" "sample" "string"]
solution(["Some another sample"]) expected ["another" "sample"]
solution(["Do, do, do, do... do it!"]) expected []
*/
const solution = sentence => {
let arrWithWords = sentence.join('').split(' ');
arrWithWords = arrWithWords.reduce((clearWords, word) => {
const clearWord = word.replace(/\W/gmi, '');
clearWords.push(clearWord);
return clearWords;
}, []);
const middleLengthOfString = arrWithWords.reduce((acc, word) => acc + word.length, 0) / arrWithWords.length;
return arrWithWords.reduce((output, word) => {
if(word.length > middleLengthOfString) {
output.push(word);
}
return output;
}, []);
}
console.log(solution(["This is a sample string"]));
console.log(solution(["Some another sample"]));
console.log(solution(["Do, do, do, do... do it!"]));
/*
Подготовка к занятию в пятницу.
Windows:
Установите все node.js скачать отсюда -> https://nodejs.org/en/
Скачайте последнюю 10.x.x версию
Для проверки установки в консоле введите "node -v" (без кавычек) отобразит версию node.js
Linux:
sudo apt install npm // установить менеджер пакетов npm
npm i -g n // установить пакет для установки node.js
sudo n latest // установить последнюю версию node.js
*/
/* TASK 1
Сделайте таблицу 5x5
При клике на элемент, изменяйте цвет у элемента на красный.
Но цвет у элемента должен изменяться пропорционально в другой половине квадрата
Пример 3х3:
[]|[]|[]
[]|[]|[]
[]|[]|[]
кликаем сюда -> []|[]|[]
[]|[]|[]
[]|[]|[x] <- загорается тут
[]|[]|[]
кликаем сюда -> []|[]|[x] <- загорается тут
[]|[]|[x]
*/
const table = document.querySelector('tbody');
const reversedRows = [...table.rows].reverse();
const reversedTable = reversedRows.reduce((output, tr) => {
output.push([...tr.cells].reverse());
return output;
}, []);
table.addEventListener('click', (e) => {
const toggleFunc = rowNumber => {
const index = e.target.cellIndex;
const cell = reversedTable[rowNumber][index];
cell.classList.toggle('active');
}
if(e.target.tagName === 'TD' && e.target.parentElement.id ==='first') {
toggleFunc(0)
}
if(e.target.tagName === 'TD' && e.target.parentElement.id ==='second') {
toggleFunc(1)
}
if(e.target.tagName === 'TD' && e.target.parentElement.id ==='third') {
toggleFunc(2)
}
if(e.target.tagName === 'TD' && e.target.parentElement.id ==='fourth') {
toggleFunc(3)
}
if(e.target.tagName === 'TD' && e.target.parentElement.id ==='fifth') {
toggleFunc(4)
}
})
// @SUPER-FrontEnd
/*
У вас есть 3 блока смотри events.html
при mousedown и движении мышки нужно сделать
ресайз одного блока.
Подсказка - событие необходимо повесить на доп. элемент .resize
*/