-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
117 lines (102 loc) · 2.89 KB
/
Copy pathindex.js
File metadata and controls
117 lines (102 loc) · 2.89 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// TASK 0
const solution = arr => {
let newArr = [];
let lastElem = arr[arr.length - 1];
arr.pop();
let tmp = function(arr) {
let index;
let leader = arr[0];
for(let i = 0; i < arr.length; i++) {
if(arr[i] >= leader) {
leader = arr[i];
index = i;
};
};
newArr.push(leader);
arr.splice(0, (index + 1));
if(arr.length > 1) {
tmp(arr);
};
};
tmp(arr);
newArr.push(lastElem);
return newArr;
};
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])); // [12, 12]
//TASK1
class Carousel {
constructor() {
this.arrImg = ["bestsportcar170.jpg", "Acura-NSX-2016-2017-02.jpg", "ferrari_667_171011.jpg"];
this.count = 0;
this.img = document.querySelector("img");
this.nextButton = document.querySelector("button.next");
this.previousButton = document.querySelector("button.previous");
this.numberImg = document.querySelector("span");
};
onclickNext() {
let pointer = this;
pointer.nextButton.onclick = function() {
if(pointer.count === (pointer.arrImg.length - 1)) {
pointer.count = -1;
}
pointer.img.src = pointer.arrImg[++pointer.count];
pointer.numberImg.textContent = pointer.count + 1;
};
};
onclickPrevious() {
let pointer = this;
pointer.previousButton.onclick = function() {
if(pointer.count <= 0) {
pointer.count = pointer.arrImg.length;
};
pointer.img.src = pointer.arrImg[--pointer.count];
pointer.numberImg.textContent = pointer.count + 1;
};
};
buttonOperation() {
this.onclickNext();
this.onclickPrevious();
}
};
let carousel = new Carousel();
carousel.buttonOperation();
//Task2
class AddStyle {
topStyle(selector, objCssStyle) {
let resultCssStr = `<style> .${selector} { `;
let styleArr = Object.keys(objCssStyle);
let propertiesCssString = styleArr.reduce((done, elem) => {
return done + `${convertingCssProperties(elem)}: ${objCssStyle[elem]};\n`;
}, '');
resultCssStr += propertiesCssString + '</style>';
let head = document.head.innerHTML;
document.head.innerHTML += resultCssStr;
};
};
let addStyle = new AddStyle();
addStyle.topStyle('fetch', {backgroundColor:'blue'});
function convertingCssProperties(str) {
let regExp = /[A-Z]/;
let index = str.search(regExp);
let substring = function(str) {
if(index !== -1) {
return `-${str[index].toLowerCase()}`;
};
};
let convertingStr = str.replace(regExp, substring(str));
return convertingStr;
};
//Super
function liquidCss(str) {
let regExp = /-[a-z]/;
let index = str.search(regExp);
let liquidCss = str.replace(regExp, str[index + 1].toUpperCase());
return liquidCss;
};
console.log(liquidCss('background-color'));
console.log(liquidCss('margin-left'));
console.log(liquidCss('flex-basis'));