-
Notifications
You must be signed in to change notification settings - Fork 0
homework_17 #21
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
base: master
Are you sure you want to change the base?
homework_17 #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>homework_17</title> | ||
<meta charset="utf-8" /> | ||
<link href='style.css' rel='stylesheet' type='text/css'> | ||
</head> | ||
<body> | ||
<div> | ||
<img src="bestsportcar170.jpg"> | ||
</div> | ||
<div class="buttons"> | ||
<button class ="previous"> <= </button> | ||
<span> 1 </span> | ||
<button class ="next"> => </button> | ||
</div> | ||
<div class="fetch"></div> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably Carousel should not be worrying about picture names. Our Carousel should only be responsible to know about
That's all. And we have to apply it in several places in every app :) without any knowledge of pictures |
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that call seems weird - because it looks like the internals of Carousel. |
||
|
||
|
||
|
||
//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')); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
img { | ||
width: 800px; | ||
height: 400px; | ||
} | ||
|
||
.buttons { | ||
margin-left: 320px; | ||
} | ||
|
||
.fetch { | ||
width: 100px; | ||
height: 100px; | ||
border: 2px solid black; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For at all, we could look at what we need from our array? We have to reduce its size but leave the same arguments.
So the first step will be to use .filter method.
A solution can look that way
So I guess it could be solved with
.filter + .some from arrays method