diff --git a/js-core/homeworks/homework-17/Acura-NSX-2016-2017-02.jpg b/js-core/homeworks/homework-17/Acura-NSX-2016-2017-02.jpg new file mode 100644 index 0000000..8c26857 Binary files /dev/null and b/js-core/homeworks/homework-17/Acura-NSX-2016-2017-02.jpg differ diff --git a/js-core/homeworks/homework-17/bestsportcar170.jpg b/js-core/homeworks/homework-17/bestsportcar170.jpg new file mode 100644 index 0000000..52b3dba Binary files /dev/null and b/js-core/homeworks/homework-17/bestsportcar170.jpg differ diff --git a/js-core/homeworks/homework-17/ferrari_667_171011.jpg b/js-core/homeworks/homework-17/ferrari_667_171011.jpg new file mode 100644 index 0000000..aeb2a89 Binary files /dev/null and b/js-core/homeworks/homework-17/ferrari_667_171011.jpg differ diff --git a/js-core/homeworks/homework-17/index.html b/js-core/homeworks/homework-17/index.html new file mode 100644 index 0000000..666d0d1 --- /dev/null +++ b/js-core/homeworks/homework-17/index.html @@ -0,0 +1,20 @@ + + + + homework_17 + + + + +
+ +
+
+ + 1 + +
+
+ + + diff --git a/js-core/homeworks/homework-17/index.js b/js-core/homeworks/homework-17/index.js new file mode 100644 index 0000000..733a60d --- /dev/null +++ b/js-core/homeworks/homework-17/index.js @@ -0,0 +1,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 = `'; + 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')); diff --git a/js-core/homeworks/homework-17/style.css b/js-core/homeworks/homework-17/style.css new file mode 100644 index 0000000..7460c47 --- /dev/null +++ b/js-core/homeworks/homework-17/style.css @@ -0,0 +1,14 @@ +img { + width: 800px; + height: 400px; +} + +.buttons { + margin-left: 320px; +} + +.fetch { + width: 100px; + height: 100px; + border: 2px solid black; +}