diff --git a/js-core/homeworks/PhoneApp/index.html b/js-core/homeworks/PhoneApp/index.html new file mode 100644 index 0000000..5e01bb0 --- /dev/null +++ b/js-core/homeworks/PhoneApp/index.html @@ -0,0 +1,25 @@ + + + + + + + Phone App + + +
+
+ My Phone App +
+
+ +
+ +
+ +
+ + + \ No newline at end of file diff --git a/js-core/homeworks/PhoneApp/src/main.css b/js-core/homeworks/PhoneApp/src/main.css new file mode 100644 index 0000000..f10361c --- /dev/null +++ b/js-core/homeworks/PhoneApp/src/main.css @@ -0,0 +1,81 @@ +body{ + font-family: Helvetica, sans-serif +} +::-webkit-scrollbar { + width: 5px; +} + +/* Track */ +::-webkit-scrollbar-track { + background: #f1f1f1; +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #858585; +} + +/* Handle on hover */ +::-webkit-scrollbar-thumb:hover { + background: #555; +} + +div.main{ + margin: auto; + position: relative; + width: 500px; + border: 1px solid #858585; + box-shadow: 0 0 15px #858585; +} +div.app-header, div.app-footer{ + text-align: center; + max-width: 478px; + width: 100%; + min-height: 25px; + color: #fff; + background: #3367d6; + padding: 15px 10px; + border: 1px solid #3367d6; +} +.app-contact-buttons{ + text-align: center; + font-size: 20px; + +} +.app-contact-buttons a{ + color:#000; +} +.app-contact-avatar, .app-contact-buttons{ + width: 13.3%; + height: 50px; + padding: 15px +} +.app-contact-avatar img{ + width: 50px; +} +.app-content{ + height:700px; + overflow:auto; + /**/ +} +.icon-link{ + text-decoration: none; + +} +tr td{ + border-bottom: 1px solid #858585; +} +tr:hover td{ + height: 60px; + border-top: 1px solid #858585; + border-bottom: 2px solid #858585; +} +tr:hover{ + cursor: pointer; + background-color: #f1f1f1; + +} +.round-avatar{ + overflow:hidden; + border-radius: 25px; +} diff --git a/js-core/homeworks/PhoneApp/src/main.js b/js-core/homeworks/PhoneApp/src/main.js new file mode 100644 index 0000000..249d6ba --- /dev/null +++ b/js-core/homeworks/PhoneApp/src/main.js @@ -0,0 +1,165 @@ +class PhoneApp{ + constructor(){ + this.database = []; + } + + addUser (user) { + let currentUser = {}; + currentUser.id = this.database.length + 1; + currentUser.avatar = user.avatar || "avatar-2" + if (user.name) { + currentUser.name = user.name; + } + if (user.phone) { + if (!this.checkPhoneNumber(user.phone)) { + currentUser.phone = user.phone; + } else { + console.log( + "не удалось сохранить номер телефона, Телефон должен состоять только из цифр" + ); + } + } + if (user.homePhone) { + if (!this.checkPhoneNumber(user.homePhone)) { + currentUser.homePhone = user.homePhone; + } else { + console.log( + "не удалось сохранить номер телефона, Телефон должен состоять только из цифр" + ); + } + } + this.database.push(currentUser); + }; + + checkPhoneNumber(phone){ + isNaN(+phone) + }; + + + deleteUser(id) { + this.database.filter((elem, index) => { + if (elem.id == id) { + this.database.splice(index, 1); + } + }); + }; + + searchUserByName(name) { + return this.database.filter(function(elem) { + if (elem.name == name) { + return elem; + } + }); + }; + + editUser(id, options) { + this.database.map(elem => { + if (elem.id == id) { + if (options.name) { + elem.name = options.name; + } + if (options.phone) { + elem.phone = options.phone; + } + if (options.homePhone) { + elem.homePhone = options.homePhone; + } + } + }); + }; + + filterUser(param) { + return this.database.filter(elem => { + if (elem[param]) { + return elem; + } + }); + }; + + sortUser(param, direction) { + return this.database.sort((a, b) => { + if (direction) { + //from small value to big value + if (direction == "up") { + return a[param] < b[param]; + } + //from big value to small value + if (direction == "down") { + return a[param] > b[param]; + } + //default + } else { + return a.id > b.id; + } + }); + }; +} + +class User{ + constructor(options){ + this.name = options.name + this.phone = options.phone + this.homePhone = options.homePhone + this.avatar = options.avatar + } +} + +let vasya = new User({ + name: "Vasya", + phone: "123456789", + homePhone: "11111" +}) +let petja = new User({ name: "Petja", phone: "123456798" }) +let brigitte = new User({ name: "Brigitte", phone: "123457689", avatar:"girl-1" }) +let tracer = new User({ name: "Tracer", phone: "123546789" }) +let anduin = new User({ + name: "Anduin", + phone: "113456789", + homePhone: "535353" +}) +let torgrim = new User({ name: "Torgrim", phone: "321456789", avatar:"man-2" }) +let anduin2 = new User({ + name: "Anduin", + phone: "113451189", + homePhone: "222222" +}) +let user = new User({ + name: "User", + phone: "113451189", + homePhone: "222222" +}) +let name = new User({ + name: "Name", + phone: "113451189", + homePhone: "222222" +}) +let someUaser = new User({ + name: "someUaser", + phone: "113451189", + homePhone: "222222" +}) +let blabla = new User({ + name: "blabla", + phone: "113451189", + homePhone: "222222" +}) + + + + +const myPhoneApp = new PhoneApp(); +myPhoneApp.addUser(vasya); +myPhoneApp.addUser(petja); +myPhoneApp.addUser(brigitte); +myPhoneApp.addUser(tracer); +myPhoneApp.addUser(anduin); +myPhoneApp.addUser(torgrim); +myPhoneApp.addUser(anduin2); +myPhoneApp.addUser(user); +myPhoneApp.addUser(name); +myPhoneApp.addUser(someUaser); +myPhoneApp.addUser(blabla); + +console.log(myPhoneApp) + +console.log(myPhoneApp.searchUserByName('Anduin')); \ No newline at end of file diff --git a/js-core/homeworks/homework-15/index.html b/js-core/homeworks/homework-15/index.html new file mode 100644 index 0000000..6e418d2 --- /dev/null +++ b/js-core/homeworks/homework-15/index.html @@ -0,0 +1,11 @@ + + + + + Home work 1 + + + + + + \ No newline at end of file diff --git a/js-core/homeworks/homework-15/src/main.js b/js-core/homeworks/homework-15/src/main.js new file mode 100644 index 0000000..84c7611 --- /dev/null +++ b/js-core/homeworks/homework-15/src/main.js @@ -0,0 +1,33 @@ +/* +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 => { + let abc = '' + +}; + +/* + 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 => {}; \ No newline at end of file diff --git a/js-core/homeworks/homework-16/index.html b/js-core/homeworks/homework-16/index.html new file mode 100644 index 0000000..6e418d2 --- /dev/null +++ b/js-core/homeworks/homework-16/index.html @@ -0,0 +1,11 @@ + + + + + Home work 1 + + + + + + \ No newline at end of file diff --git a/js-core/homeworks/homework-16/src/main.js b/js-core/homeworks/homework-16/src/main.js new file mode 100644 index 0000000..c241308 --- /dev/null +++ b/js-core/homeworks/homework-16/src/main.js @@ -0,0 +1,144 @@ +/* +0 Алгоритмы +Реализуйте функцию которая будет превращать трехмерный массив +в двухмерный, а если массив двухмерный, тогда в трехмерный массив +// solution([ [1, 'a'], [2, 'b'], [3, 'c'] ]) => [ [1, 2, 3], [a, b, c] ] +// solution([ [1, 3, 5], [2, 4, 6] ]) => [ [1, 2], [3, 4], [5, 6] ] +// solution([[]]) => [] +[ [ [ ] ] ] = [ [] ] +ИСПОЛЬЗУЙТЕ МЕТОДЫ МАССИВОВ ! +*/ + +// solution([[1, 3, 5], [2, 4, 6]]); +// solution([[1, 'a'], [2, 'b'], [3, 'c']]); + +// const solution = arr => {}; + +const navigation = [ + {name: 'Главная'}, + { + name: 'Каталог', + children: [ + { + name: 'Компьютеры', + children: [{name: 'Ноутбуки'}, {name: 'Планшеты'}] + } + ] + }, + {name: 'Профиль'} +]; + +class Items{ + constructor(){ + this.ul + } + + createStructure(arr){ + let body = document.body + arr.map(elem => { + let keys = Object.keys(elem); + body.innerHTML += this.createH1(elem) + if(keys.includes('children')){ + body.innerHTML +="" + this.ul = document.querySelector('ul'); + this.children(elem) + } + }) + } + + children(elem){ + elem.children.map(innerElem => { + this.ul.innerHTML += this.createH1(innerElem) + this.createLi(innerElem.children) + }) + } + + createH1(elem){ + return `

${elem.name}

` + } + + createLi(elem){ + let innerUl = this.ul.innerHTML + innerUl.innerHTML += `` + + } +} + + +let obj = new Items() +obj.createStructure(navigation) + +/* +Визуализируйте массив, если в коллекции есть свойство +children, +тогда создайте вложенный лист +name - свойство h1 +children ul -> li +Используйте innerHTML +*/ + +/* +

Main

+