Skip to content
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

домашнее 15 0-таск и визуализация таблицы #16

Open
wants to merge 2 commits 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
13 changes: 13 additions & 0 deletions js-core/homeworks/homework-15/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Homework-16</title>
</head>
<body>


<script src="src/main.js"></script>
</body>
</html>

139 changes: 139 additions & 0 deletions js-core/homeworks/homework-15/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
TASK 0
Проверьте что строка содержит все символы от "a" до "z"
solution("wyyga") // false
solution("qwertyuioplkjhgfdsazxcvbnm") // true
solution("ejuxggfsts") // false
solution("qpwoeirutyalskdjfhgmznxbcv") // true
solution("qqqqqqqqpwoeirutyallskkdjfhgmmznxbcv") // true
solution("0123456789abcdefghijklmnop") // false
*/

/*Мне такое решение самой не нравиться, но лучше я не придумала((( */

const solution = str => {
var newStr = str.replace(/a/, '$').replace(/b/, '$').replace(/c/, '$').replace(/d/, '$')
.replace(/e/, '$').replace(/f/, '$').replace(/g/, '$').replace(/h/, '$')
Copy link
Member

Choose a reason for hiding this comment

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

wow :)

.replace(/i/, '$').replace(/j/, '$').replace(/k/, '$').replace(/l/, '$')
.replace(/m/, '$').replace(/n/, '$').replace(/o/, '$').replace(/p/, '$')
.replace(/q/, '$').replace(/r/, '$').replace(/s/, '$').replace(/t/, '$')
.replace(/u/, '$').replace(/v/, '$').replace(/w/, '$').replace(/x/, '$')
.replace(/y/, '$').replace(/z/, '$');
var newArr = newStr.split('');
var count = 0;
newArr.forEach(elem => {
if (elem === '$') {
count ++;
}
});
if (count === 26) {
console.log(true)
} else {
console.log(false)
}

};

solution("wyyga"); //false
solution("qwertyuioplkjhgfdsazxcvbnm");//true
solution("0123456789abcdefghijklmnop"); //false
solution("qpwoeirutyalskdjfhgmznxbcv");// true
solution("qqqqqqqqpwoeirutyallskkdjfhgmmznxbcv");// true
solution("0123456789abcdefghijklmnop");// false

/*
2. Напишите функция которая преобразовывает / открывает
скобки всех вложенных внутри массивов
Необходимо реализовать рекурсивный фызов функции.
Функция должна открывать любое количество
внутренних массивов и объектов
example:
[[1,2],[3,[4]],5, 10] => [1, 2, 3, 4, 5, 10]
[25, 10, [10, [15]]] => [25, 10, 10, 15]
[1, [2, [ {a: "b", c: 'd' }, { c: [1, 2, 5] } ] ] ] => [1, 2, {a: "b"}]
*/

//#1 arr == [...] flattenedArray = [1] + flatten = [2, [{a: "b"}, { c: 'd' }]]
//#2 arr == [2, [ {a: "b"}, { c: 'd' } ] ] flattenedArray = [2] + flatten == [{a: "b"}, { c: 'd' }]
//#3 arr == [ {a: "b"}, { c: 'd' } ] flattenedArray = [{a: "b"}, { c: 'd' }]
//#
const flatten = arr => {

};


/* Рекурсия не получиласьБ решение со сплайсами у меня в 5 хомверке*/


/*
Виртуализировать таблицу, сделать рендер всей
таблицы через JavaScript.
Второй макет.
https://github.com/aleksandra-maslennikova/telephone-book/blob/master/index.html
Выглядеть должно так же: https://aleksandra-maslennikova.github.io/telephone-book/index.html
*/

const users = [
{
name: 'Иван',
lastName: 'Петров',
email: 'ivanpetrov@gmail.com'
},
{
name: 'Сергей',
lastName:'Сергеев',
email: 'sergeysergeev@gmail.com'
},
{
name: 'Иван',
lastName: 'Петров',
email: 'ivanpetrov@gmail.com'
},
{
name: 'Александр',
lastName: 'Александров',
email: 'alex@gmail.com'
},
{
name: 'Алекс',
lastName: 'Смирнов',
email: 'smirnov@gmail.com'
},
];
const colums = ['Name', 'LastName', 'Email'];
const app = {
Copy link
Member

Choose a reason for hiding this comment

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

please make class instead of object

users,
colums,
newEl(elName) {
return document.createElement(elName);
},
render() {
const main = this.newEl('main');
const table = this.newEl('table');
const tr = this.newEl('tr');
colums.forEach( columName => {
const th = this.newEl('th');
th.textContent = columName;
tr.appendChild(th);

});
table.appendChild(tr);
users.forEach(user => {
const tr = this.newEl('tr');
const td1 = this.newEl('td');
td1.textContent = user.name;
const td2 = this.newEl('td');
td2.textContent = user.lastName;
const td3 = this.newEl('td');
td3.textContent = user.lastName;
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
table.appendChild(tr);
});
main.appendChild(table);
document.body.appendChild(main);
}
};

app.render();