|
| 1 | +// TASK 1 |
| 2 | +const solution = str => { |
| 3 | + let regExpLetter = /[a-z]/g; |
| 4 | + let regExpNunber = /[0-9]/; |
| 5 | + if(str.search(regExpNunber) === 0){ |
| 6 | + return false; |
| 7 | + }; |
| 8 | + if(str.search(regExpLetter) === 0) { |
| 9 | + let arrFromRegExp = str.match(regExpLetter); |
| 10 | + let newArrWithoutRepetition = []; |
| 11 | + for(let i = 0; i < arrFromRegExp.length; i++) { |
| 12 | + for(let k = 0; k < newArrWithoutRepetition.length; k++) { |
| 13 | + if(newArrWithoutRepetition[k] == arrFromRegExp[i]) { |
| 14 | + newArrWithoutRepetition.splice(k, 1); |
| 15 | + }; |
| 16 | + }; |
| 17 | + newArrWithoutRepetition.push(arrFromRegExp[i]); |
| 18 | + }; |
| 19 | + if(newArrWithoutRepetition.length === 26 ) { |
| 20 | + return true; |
| 21 | + } else{ |
| 22 | + return false; |
| 23 | + }; |
| 24 | + }; |
| 25 | +}; |
| 26 | + |
| 27 | +console.log('Task1 ---> ', solution("wyyga"));//false |
| 28 | +console.log('Task1 ---> ', solution("qwertyuioplkjhgfdsazxcvbnm")); //true |
| 29 | +console.log('Task1 ---> ', solution("ejuxggfsts")); //false |
| 30 | +console.log('Task1 ---> ', solution("qpwoeirutyalskdjfhgmznxbcv")); //true |
| 31 | +console.log('Task1 ---> ', solution("qqqqqqqqpwoeirutyallskkdjfhgmmznxbcv")); //true |
| 32 | +console.log('Task1 ---> ', solution("0123456789abcdefghijklmnop")); //false |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +//TASK2 |
| 37 | +const flatten = arr => { |
| 38 | + let arr2 = []; |
| 39 | + arr.forEach((elem) => { |
| 40 | + if(!Array.isArray(elem)) { |
| 41 | + arr2.push(elem); |
| 42 | + } else { |
| 43 | + arr2 = arr2.concat(flatten(elem)); |
| 44 | + }; |
| 45 | + }); |
| 46 | + return arr2; |
| 47 | +}; |
| 48 | + |
| 49 | +console.log('Task2 ---> ', flatten([1, [2, [ {a: "b", c: 'd' }, { c: [1, 2, 5] } ] ] ])); |
| 50 | +console.log('Task2 ---> ', flatten([[1,2],[3,[4]],5, 10])); |
| 51 | +console.log('Task2 ---> ', flatten([25, 10, [10, [15]]])); |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +//Task3 |
| 57 | +const dataUsers = [ |
| 58 | + { |
| 59 | + name: 'Иван', |
| 60 | + lastName: 'Петров', |
| 61 | + email: 'IvanPetrov@ec.ua' |
| 62 | + }, |
| 63 | + { |
| 64 | + name: 'Сергей', |
| 65 | + lastName: 'Сергей', |
| 66 | + email: 'SergeiSergeev@ec.ua' |
| 67 | + }, |
| 68 | + { |
| 69 | + name: 'Иван', |
| 70 | + lastName: 'Иванов', |
| 71 | + email: 'IvanIvanov@ec.ua' |
| 72 | + }, |
| 73 | + { |
| 74 | + name: 'Александр', |
| 75 | + lastName: 'Александров', |
| 76 | + email: 'AlexAlex@ec.ua' |
| 77 | + }, |
| 78 | + { |
| 79 | + name: 'Алекс', |
| 80 | + lastName: 'Смирнов', |
| 81 | + email: 'AlexSmirnov@ec.ua' |
| 82 | + }, |
| 83 | + { |
| 84 | + name: 'Сергей', |
| 85 | + lastName: 'Волков', |
| 86 | + email: 'VolkovSergey@ec.ua' |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'Мария', |
| 90 | + lastName: 'Шарапова', |
| 91 | + email: 'MariyaSharapova@ec.ua' |
| 92 | + }, |
| 93 | + { |
| 94 | + name: 'Александр', |
| 95 | + lastName: 'Винник', |
| 96 | + email: 'AlexVinnik@ec.u' |
| 97 | + }, |
| 98 | + { |
| 99 | + name: 'Дарий', |
| 100 | + lastName: 'Смирнов', |
| 101 | + email: 'DariySmirnov@ec.ua' |
| 102 | + }, |
| 103 | + { |
| 104 | + name: 'Елена', |
| 105 | + lastName: 'Лещенко', |
| 106 | + email: 'ElenaLeshenko@ec.ua' |
| 107 | + }, |
| 108 | + { |
| 109 | + name: 'Ольга', |
| 110 | + lastName: 'Новикова', |
| 111 | + email: 'OlgaNovikova@ec.ua' |
| 112 | + }, |
| 113 | + { |
| 114 | + name: 'Наталья', |
| 115 | + lastName: 'Шемякина', |
| 116 | + email: 'ShemyakinaN@ec.ua' |
| 117 | + }, |
| 118 | + { |
| 119 | + name: 'Анна', |
| 120 | + lastName: 'Донцова', |
| 121 | + email: 'AnnaDontsova@ec.ua' |
| 122 | + }, |
| 123 | + { |
| 124 | + name: 'Влад', |
| 125 | + lastName: 'Яма', |
| 126 | + email: 'VladYama@ec.ua' |
| 127 | + }, |
| 128 | + { |
| 129 | + name: 'Кира', |
| 130 | + lastName: 'Воробьева', |
| 131 | + email: 'Kira1990@ec.ua' |
| 132 | + }, |
| 133 | + { |
| 134 | + name: 'Виктор', |
| 135 | + lastName: 'Кривенко', |
| 136 | + email: 'ViktorKriv@ec.ua' |
| 137 | + } |
| 138 | +]; |
| 139 | + |
| 140 | +const columnHeadings = ['Name', 'Last name', 'Email']; |
| 141 | + |
| 142 | +function render() { |
| 143 | + let createNewElement = function(newElem) { |
| 144 | + return document.createElement(newElem); |
| 145 | + }; |
| 146 | + let table = createNewElement('table'); |
| 147 | + table.setAttribute('class', 'table table-hover contacts'); |
| 148 | + let insert = document.querySelector('main > div'); |
| 149 | + let thead = createNewElement('thead'); |
| 150 | + table.appendChild(thead); |
| 151 | + let tr = createNewElement('tr'); |
| 152 | + thead.appendChild(tr); |
| 153 | + columnHeadings.forEach((elem) => { |
| 154 | + let th = createNewElement('th'); |
| 155 | + th.textContent = elem; |
| 156 | + tr.appendChild(th); |
| 157 | + }); |
| 158 | + let tbody = createNewElement('tbody'); |
| 159 | + table.appendChild(tbody); |
| 160 | + dataUsers.forEach((elem) => { |
| 161 | + let trInTbody = createNewElement('tr') |
| 162 | + tbody.appendChild(trInTbody); |
| 163 | + let arrObjkeys = Object.keys(elem); |
| 164 | + arrObjkeys.forEach((elemTd) => { |
| 165 | + let td = createNewElement('td'); |
| 166 | + td.textContent = elem[elemTd]; |
| 167 | + trInTbody.appendChild(td); |
| 168 | + }); |
| 169 | + }); |
| 170 | + return insert.appendChild(table); |
| 171 | +}; |
| 172 | + |
| 173 | +render(); |
0 commit comments