-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
76 lines (64 loc) · 2.34 KB
/
Copy pathmain.js
File metadata and controls
76 lines (64 loc) · 2.34 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
/* 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 []
*/
function removePunctuation(string) {
return string.replace(/[.,!?]/g, "")
}
function solution (arr) {
let wordsArr = arr[0].split(' ').map(word => {
return removePunctuation(word)
});
let lengthsArr = wordsArr.map(word => {
return word.length
});
let sumLengthsArr = 0;
lengthsArr.forEach(length => {
return sumLengthsArr += length;
});
let averageLength = sumLengthsArr/lengthsArr.length;
let res = wordsArr.filter(word => {
if(word.length > averageLength) {
return word;
}
});
console.log(res);
}
solution(["This is a sample string"]);
solution(["Some another sample"]);
solution(["Do, do, do, do... do it!"]);
/* TASK 1
Сделайте таблицу 5x5
При клике на элемент, изменяйте цвет у элемента на красный.
Но цвет у элемента должен изменяться пропорционально в другой половине квадрата
Пример 3х3:
[]|[]|[]
[]|[]|[]
[]|[]|[]
кликаем сюда -> []|[]|[]
[]|[]|[]
[]|[]|[x] <- загорается тут
[]|[]|[]
кликаем сюда -> []|[]|[x] <- загорается тут
[]|[]|[x]
*/
/* C делегированием я не смогла сделать */
let table = document.querySelector('table');
// table.addEventListener('click', (event) => {
// if (event.target.tagName === 'TD') {
// }
// });
/* Только присвоением события на каждый элемент*/
let cells = document.querySelectorAll('td');
for (let i = 0; i < cells.length; i++) {
cells[i].addEventListener('click', () => {
let number = cells.length - 1 - i;
cells[number].style.background = 'red';
})
}