-
Notifications
You must be signed in to change notification settings - Fork 0
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
Homework 14 #12
base: master
Are you sure you want to change the base?
Homework 14 #12
Changes from 2 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,97 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Home work 14</title> | ||
<style> | ||
*{ | ||
margin:0; | ||
padding: 0; | ||
font-size: 16px; | ||
font-family: Arial; | ||
box-sizing: border-box; | ||
} | ||
div.test-block{ | ||
margin: 20px 50px; | ||
} | ||
div.test-block p{ | ||
text-align: center; | ||
margin-bottom: 40px; | ||
} | ||
form > ol{ | ||
padding-left: 25px; | ||
margin-bottom: 25px; | ||
} | ||
form > ol > li { | ||
margin-bottom: 25px; | ||
} | ||
form > ol > li > ul { | ||
margin-top: 15px; | ||
} | ||
form > ol > li > ul > li{ | ||
list-style: none; | ||
padding: 5px 0; | ||
} | ||
form input{ | ||
background-color: lightblue; | ||
} | ||
form input[type='submit']{ | ||
padding: 7px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<script src="src/main.js"></script> | ||
|
||
|
||
<!-- <div class="test-block"> | ||
<p>Тест по програмированию</p> | ||
|
||
<form> | ||
<ol> | ||
<li>Вопрос номер 1 | ||
<ul> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №1</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №2</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №3</label> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Вопрос номер 2 | ||
<ul> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №1</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №2</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №3</label> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Вопрос номер 3 | ||
<ul> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №1</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №2</label> | ||
</li> | ||
<li> | ||
<label><input type="checkbox" name="anwer"> вариант ответа №3</label> | ||
</li> | ||
</ul> | ||
</li> | ||
</ol> | ||
<p> <input type="submit" name="submit" value="Проверить мои результаты"></p> | ||
</form> | ||
</div> --> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
TASK 0. Найдите числа которые повторяются нечетное количество раз | ||
в массиве | ||
solution([12, 23, 34, 12, 12, 23, 12, 45]) -> [34 45] | ||
solution([4, 4, 100, 5000, 4, 4, 4, 4, 4, 100, 100,]) -> [4 100 5000] | ||
solution([3, 3, 4, 6, 4, 5, 9, 9, 21, 9]) -> [6 5 9 21] | ||
solution([4, 8, 15, 16, 23, 42, 4, 15, 42, 42]) -> [8 16 23 42] | ||
solution([2, 2, 44, 44]) => [] | ||
*/ | ||
|
||
|
||
function solution(arr){ | ||
let _temp = {} | ||
arr.forEach( function(element, index) { | ||
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. it's a nice place to use Array.prototype.reduce 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. Done |
||
if(_temp[element]){ | ||
_temp[element]++ ; | ||
}else{ | ||
_temp[element] = 1; | ||
} | ||
// statements | ||
}); | ||
|
||
let res = []; | ||
|
||
Object.keys(_temp).forEach(function(value){ | ||
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. your solution looks similar to Sergey are you worked a pair-programming? 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. Nope.... 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. Is solution wrong& what I must to do with your comment? |
||
if(_temp[value] % 2 !== 0){ | ||
res.push(value); | ||
} | ||
}); | ||
|
||
return res; | ||
|
||
} | ||
console.log(solution([12, 23, 34, 12, 12, 23, 12, 45])); | ||
console.log(solution([4, 4, 100, 5000, 4, 4, 4, 4, 4, 100, 100,])); | ||
console.log(solution([3, 3, 4, 6, 4, 5, 9, 9, 21, 9])); | ||
console.log(solution([4, 8, 15, 16, 23, 42, 4, 15, 42, 42])); | ||
console.log(solution([2, 2, 44, 44])); | ||
|
||
|
||
|
||
const someWebpackModule = `module.exports = { | ||
context: %%HOMEDIR%, | ||
entry: { | ||
app: "%%HOMEDIR%%/%%APP_DIR%%/%%APPNAME%%.js" | ||
}, | ||
output: { | ||
path: %%HOMEDIR%% + '/app', | ||
filename: "dist/[%%APPNAME%%].js", | ||
library: '[%%APPNAME%%]' | ||
} | ||
}`; | ||
|
||
/* TASK - 1 | ||
Распарсите строку и замените | ||
%%HOMEDIR%% -> './JavaScript-Basic' | ||
%%APP_DIR%% -> 'fixtures/src' | ||
%%APPNAME%% -> 'app.js' | ||
Вам нужно написать функцию которая в зависимости от разных параметров | ||
будет изменять заданные значения на необходимые вам | ||
Сделайте несколько вызовов данной функции | ||
* | ||
* */ | ||
|
||
let replaceInfo = [ | ||
{ | ||
template: '%%HOMEDIR%%', | ||
templateFlags: 'gmi', | ||
replaceString: './JavaScript-Basic' | ||
}, | ||
{ | ||
template: '%%APP_DIR%%', | ||
templateFlags: 'gmi', | ||
replaceString: 'fixtures/src' | ||
}, | ||
{ | ||
template: '%%APPNAME%%', | ||
templateFlags: 'gmi', | ||
replaceString: 'app.js' | ||
} | ||
] | ||
|
||
function grandReplace(string, data){ | ||
let res = string; | ||
|
||
return data.reduce(function(acc,elem){ | ||
let regexp = new RegExp(elem.template,elem.templateFlags); | ||
return acc.replace(regexp,elem.replaceString) | ||
},string); | ||
} | ||
|
||
console.log(grandReplace(someWebpackModule,replaceInfo)); | ||
|
||
|
||
/* | ||
TASK - 2 | ||
Сделайте разметку как скриншоте используя HTML | ||
вам необходимо использовать тэги(!) | ||
*/ | ||
|
||
|
||
|
||
|
||
|
||
/* | ||
TASK 3 | ||
JavaScript => | ||
Создать объект с методами, которые будут динамически генерировать DOM | ||
Это будет тест, который мы будем разрабатывать в следующих заданиях. | ||
Сейчас вам нужно только динамически создать html, | ||
методы должны храниться в одном объекте. | ||
Изначально на странице должен быть только <body>, | ||
вызывая методы объекта нужно создать dom-элементы | ||
*/ | ||
let app = { | ||
render(){ | ||
let div = document.createElement('div'); | ||
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. you have very huge "render" method which doing a lot of job. That has roles:
It will be much better to make a smaller function which would have only 1 responsibility, and than connect such parts inside render 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. I've made smaller render function. |
||
div.setAttribute("class", "test-block"); | ||
|
||
let head = document.createElement('p'); | ||
head.innerText = 'Тест по програмированию' | ||
div.appendChild(head); | ||
|
||
let form = document.createElement('form'); | ||
|
||
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. please remove blank line here. 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. I've deleted blank rows |
||
let questionList = document.createElement('ol'); | ||
|
||
let questions = [ | ||
{ | ||
question : 'Вопрос номер 1', | ||
answers: [ | ||
'вариант ответа 1', | ||
'вариант ответа 2', | ||
'вариант ответа 3' | ||
] | ||
}, | ||
{ | ||
question : 'Вопрос номер 2', | ||
answers: [ | ||
'вариант ответа 1', | ||
'вариант ответа 2', | ||
'вариант ответа 3' | ||
] | ||
}, | ||
{ | ||
question : 'Вопрос номер 3', | ||
answers: [ | ||
'вариант ответа 1', | ||
'вариант ответа 2', | ||
'вариант ответа 3' | ||
] | ||
} | ||
] | ||
|
||
questions.forEach((questionObj,questionIndex)=>{ | ||
let questionBlock = document.createElement('li'); | ||
questionBlock.innerText = questionObj.question; | ||
|
||
let answersBlock = document.createElement('ul'); | ||
|
||
questionObj.answers.forEach( (answerText) => { | ||
|
||
let answerLi = document.createElement('li'); | ||
let labelForAnswer = document.createElement('label'); | ||
|
||
let inputAnswer = document.createElement('input'); | ||
inputAnswer.type = 'checkbox'; | ||
inputAnswer.name = 'answer_question_' + (questionIndex + 1); | ||
|
||
labelForAnswer.appendChild(inputAnswer); | ||
|
||
let answerNode = document.createTextNode(answerText); | ||
labelForAnswer.appendChild(answerNode); | ||
answerLi.appendChild(labelForAnswer); | ||
|
||
// answer.innerText = answerText; | ||
answersBlock.appendChild(answerLi); | ||
}); | ||
|
||
questionBlock.appendChild(answersBlock); | ||
|
||
|
||
questionList.appendChild(questionBlock); | ||
|
||
|
||
}); | ||
|
||
|
||
let buttonBlock = document.createElement('p'); | ||
|
||
let buttonSubmit = document.createElement('input'); | ||
buttonSubmit.type = 'submit'; | ||
buttonSubmit.name = 'submit'; | ||
buttonSubmit.value = 'Проверить мои рещультаты' | ||
|
||
buttonBlock.appendChild(buttonSubmit); | ||
|
||
form.appendChild(questionList).appendChild(buttonBlock); | ||
|
||
div.append(form); | ||
|
||
document.body.appendChild(div); | ||
// console.log(div); | ||
|
||
} | ||
} | ||
|
||
|
||
app.render(); |
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.
please do not commit commented code it makes it hard to understand if it a mistake or commented solution or what do you really mean.
Your homework should be clear without commented code
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.
Deleted