Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions js-core/homeworks/homework-18/event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
section {
display: flex;
width: 100%;
height: 350px;
flex: 1;
}
div {
flex: 1;
flex-direction: column;
display: flex;
align-items: flex-end;
}
.one {
background-color: coral;
}
.two {
background-color: slateblue;
}
.three {
background-color: fuchsia;
}
.resize {
width: 25px;
height: 100%;
background: black;
transition: 0.3s ease;
}
</style>
</head>

<body>
<section>
<div class="one">
<div class="resize"></div>
</div>
<div class="two">
<div class="resize"></div>
</div>
<div class="three">
<div class="resize"></div>
</div>
</section>
<script src="events.js"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions js-core/homeworks/homework-18/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @SUPER-FrontEnd
/*
У вас есть 3 блока смотри events.html
при mousedown и движении мышки нужно сделать
ресайз одного блока.
Подсказка - событие необходимо повесить на доп. элемент .resize
*/

const resizeBlocks = document.querySelectorAll('.resize');

[...resizeBlocks].forEach(block => {
console.log(block)
block.addEventListener('click', (e) => {
console.log(e.target.parentElement)
});
})
61 changes: 61 additions & 0 deletions js-core/homeworks/homework-18/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home work 18</title>
<style>
body{
display: flex;
justify-content: center;
}
.active{
background-color: brown;
}
td{
width: 50px;
height: 50px;
border: 2px solid black;
}
</style>
</head>
<body>
<table>
<tr id="first">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr id="second">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr id="third">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr id="fourth">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr id="fifth">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<script src="src/main.js"></script>
</body>
</html>
98 changes: 98 additions & 0 deletions js-core/homeworks/homework-18/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(!e.target.tagName === 'TD') {
 return 
}

if(!e.target.tagName === 'TD') {
return;
}

const hashMap = {
'first': 0,
'second': 1,
'third': 2,
'fourth': 3,
'fifth': 4
}

if(hashMap[e.target.parentElement.id] || !hashMap[e.target.parentElement.id]) {
toggleFunc(hashMap[e.target.parentElement.id])
}
})

// @SUPER-FrontEnd
/*
У вас есть 3 блока смотри events.html
при mousedown и движении мышки нужно сделать
ресайз одного блока.
Подсказка - событие необходимо повесить на доп. элемент .resize
*/