Skip to content

home work 17 #26

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions js-core/homeworks/homework-17/homework-17.0/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home work 1</title>
</head>
<body>

<script src="src/main.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions js-core/homeworks/homework-17/homework-17.0/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
TASK 0
Отобразите всех лидеров массива.
*
*
* Элемент лидер если он больше чем все последующие элементы
* после него ( элементы справа ).
* Последний элемент всегда лидер. Например в массиве [16,17,4,3,5,2]
* лидеры 17, 5 и 2.
*
* */

const solution = arr => {
let mass = arr.filter((value, i, arr) => {
if (i + 1 == arr.length) {
return value;
}
let a = arr.slice(i + 1)
//console.log(`a = `, a);

function compareNumeric(a, b) {
if (a > b) return -1;
if (a < b) return 1;
}
a.sort(compareNumeric);
if (value > a[0]) {
return value;
}

});
return mass;

};

console.log(solution([16, 17, 4, 3, 5, 2])); // === [17, 5, 2]
console.log(solution([4, 3, 7, 12, 6, 67, 5, 45, 34, 35, 2, 8])); // [67, 45, 35, 8]
console.log(solution([12, 10, 12, 8, 7, 6])); // [12, 8, 7, 6]
console.log(solution([1, 2, 3, 4, 5, 4])); // [5, 4]
console.log(solution([12, 12, 12])); // [5, 4]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions js-core/homeworks/homework-17/homework-17.1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Home work карусель</title>
<style>

</style>
</head>

<body>
<div>
<img id="img" src="img/download1.jpg" alt="">

<div>
<button id="left">назад</button>
<span id="num">1</span>
<button id="right">вперед</button>
</div>
</div>
<script src="src/main1.js"></script>
<script src="src/main.js"></script>
</body>

</html>
11 changes: 11 additions & 0 deletions js-core/homeworks/homework-17/homework-17.1/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var arr = ['img/download1.jpg', 'img/download2.jpg', 'img/download3.jpg', 'img/download4.jpg', 'img/download5.jpg']
Copy link
Member

Choose a reason for hiding this comment

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

этот момент мне непонятен, т.е мне как пользователя нужно будет знать названия картинок и после их передавать в карусель ? Выглядит странно.

Обычно контракт слайдеры выглядит таким образом

  • Класс родителя элементов
  • Иногда класс детей внутри этого родителя( но обычно эта структура жестка указана в Каруселе)

И картинки все статичны есть в HTML, мне недоконца понятно почему ты выбрал такую структуру, какую проблемы ты пытался решить ?

left = document.getElementById('left');
right = document.getElementById('right');
var carousel = new Carousel(arr);
left.onclick = function() {
carousel.left1();
}
right.onclick = function() {
carousel.right1();
}
carousel.set(2000)
78 changes: 78 additions & 0 deletions js-core/homeworks/homework-17/homework-17.1/src/main1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// class Carousel {
// constructor() {
// this.img = document.getElementById('img');
// this.left = document.getElementById('left');
// this.right = document.getElementById('right');
// this.num = document.getElementById('num');
// }
// left1() {
// var e = this.img.src.match(/download[1-5]/)[0];
// var i = e[e.length - 1];
// i--;
// if (i == 0) { i = 5 };
// this.img.src = this.img.src.replace(/download[1-5]/, `download${i}`);
// this.num.textContent = i;
// }
// right1() {
// var e = this.img.src.match(/download[1-5]/)[0];
// var i = e[e.length - 1];
// i++;
// if (i == 6) { i = 1 };
// this.img.src = this.img.src.replace(/download[1-5]/, `download${i}`);
// this.num.textContent = i;
// }
// setInt() {
// function fun() {
// var e = this.img.src.match(/download[1-5]/)[0];
// var i = e[e.length - 1];
// i++;
// if (i == 6) { i = 1 };
// this.img.src = this.img.src.replace(/download[1-5]/, `download${i}`);
// this.num.textContent = i;
// }
// setInterval(fun, 2000)
// }
// }
// var carousel = new Carousel();
// left.onclick = function() {
// carousel.left1();
// }
// right.onclick = function() {
// carousel.right1();
// }
// carousel.setInt();
function include(url) {
var script = document.createElement('script');
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
class Carousel {
constructor(arr) {
this.img = document.getElementById('img');
this.num = document.getElementById('num');
this.i = 0;
this.img.src = arr[0];
}
left1() {
this.i--;
if (this.i < 0) { this.i = 4 }
this.img.src = arr[this.i];
this.num.textContent = this.i + 1;
}
right1() {
this.i++;
if (this.i > 4) { this.i = 0 }
this.img.src = arr[this.i];
this.num.textContent = this.i + 1;
console.log(this.i)
}
set(time) {
let f = () => {
this.i++;
if (this.i > 4) { this.i = 0 }
this.img.src = arr[this.i];
this.num.textContent = this.i + 1;
}
setInterval(f, time);
}
}
24 changes: 24 additions & 0 deletions js-core/homeworks/homework-17/homework-17.2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Home work 1</title>
<style>
body {
background-color: aquamarine;
}

.ff {
background-color: rgb(197, 127, 255);
}
</style>
</head>

<body>
<h1 class="fetch">tttttttttttttt</h1>
<span class="top">eeeeeee</span>
<script src="src/main.js"></script>
</body>

</html>
21 changes: 21 additions & 0 deletions js-core/homeworks/homework-17/homework-17.2/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var t = document.styleSheets;
//console.log(t[0].rules)
class Set {
constructor() {

}
topStyle(class1, atribut) {
var style = document.getElementsByTagName('style')[0];
let atribut1 = ''
for (let key in atribut) {
console.log(`${key}:${atribut[key]}`);
atribut1 += `${key}:${atribut[key]}`
}
var c = ' .' + class1 + ' {' + atribut1 + '};';
style.innerHTML += c;
//head.appendChild(style);
}
}
var s = new Set();
//s.topStyle('fetch', { border: '4px double black;' });
s.topStyle('top', { backgroundColor: 'blue' });