anton123 před 1 rokem
rodič
revize
d54629bedd
2 změnil soubory, kde provedl 437 přidání a 0 odebrání
  1. 251 0
      Массивы.js
  2. 186 0
      Обьекты.js

+ 251 - 0
Массивы.js

@@ -0,0 +1,251 @@
+//Confirms
+{
+    const arr = [confirm('Ты мужчина?'),confirm('Ты женщина?'),confirm('Тебе больше 18-ти лет?')]
+    console.log(arr)//[true, false, true]
+}
+
+//Prompts
+{
+    const arr = []
+    arr[0]=prompt('Ты мужчина?')
+    arr[1]=prompt('Ты женщина?')
+    arr[2]=prompt('Тебе больше 18-ти лет?')
+    console.log(arr)// ['да', 'нет', 'да']
+}
+
+//Item access 
+{
+    const arr = ['нулевой','первый','второй']
+    indexArr = prompt('Введите индекс массива')
+    console.log(arr[indexArr])
+}
+
+//Item change
+{
+    const arr = ['нулевой','первый','второй']
+    indexArr = prompt('Введите индекс массива')//если тут будет '2'
+    meaningArr = prompt('Введите значение для выбраного индекса')// а тут слово 'четвертый'
+    arr[indexArr]= meaningArr
+    console.log(arr)// то здесь будет такой массив ['нулевой', 'первый', 'четвертый']
+}
+
+//Multiply table
+{
+    //const arr = [[],[0,1,2,3,4,5,6,7,8,9,10],[0,2,4,6,8,10,12,14,16,18,20],[0,3,6,9,12,15,18,21,24,27,30],[0,4,8,12,16,20,24,28,32,36,40],[0,5,10,15,20,25,30,35,40,45,50]]
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    console.log(arr[3][4])// ответ 12
+}
+
+//Multiply table slice
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    let arr2 = [arr[1].slice(1),arr[2].slice(1),arr[3].slice(1),arr[4].slice(1)]
+}
+
+
+//IndexOf Word
+{
+    let str = prompt('Введите строку из несколький слов').split(' ');
+    let strIndex = prompt('Введите искомое слово');
+    let arr = str.indexOf(strIndex);
+    if (arr === -1){
+        alert('Слово не найдено');
+    }
+    else{alert('Ваше слово '+(arr+1)+'-е по счету');}
+}
+
+
+//Reverse
+{
+    let arr = []
+    arr.push(prompt('Введите первый элемент'))
+    arr.push(prompt('Введите второй элемент'))
+    arr.push(prompt('Введите третий элемент'))
+    arr.push(prompt('Введите четвертый элемент'))
+    arr.push(prompt('Введите пятый элемент'))
+    let arr2 = []
+    arr2.push(arr.pop())
+    arr2.push(arr.pop())
+    arr2.push(arr.pop())
+    arr2.push(arr.pop())
+    arr2.push(arr.pop())
+    console.log(arr2)
+//Reverse 2
+    let arr3 = []
+    arr3.unshift(arr2.shift())
+    arr3.unshift(arr2.shift())
+    arr3.unshift(arr2.shift())
+    arr3.unshift(arr2.shift())
+    arr3.unshift(arr2.shift())    
+}
+
+
+//Copy
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    const arr2 = arr
+}
+
+//Deep Copy
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    const arr2 = arr.slice()
+}
+
+//Array Equals
+{
+    const arr = [1,2,3]
+    const arr2 = arr
+    arr === arr2//true
+}
+
+//Flat
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    const arr2 = [...arr[0],...arr[1],...arr[2],...arr[3],...arr[4]]
+    console.log(arr2.length)//25 
+}
+
+//Destruct
+{
+    let str = prompt('Введите текст')
+    const [a,,,,b,,,,c] = str
+    alert(a+b+c)
+}
+
+//Destruct default
+{
+    let str = prompt('Введите текст')
+    const [a='!',,,,b='!',,,,c='!'] = str
+    alert(a+b+c)
+}
+
+//Multiply table rest
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    const [,[,...a],[,...b],[,...c],[,...d]] = arr
+    const arr2 = [a,b,c,d]
+    const arr3 = [...arr2[0],...arr2[1],...arr2[2],...arr2[3]]
+    console.log(arr3) // [1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16]
+}
+
+//For Alert
+{
+    const names    = ["John", "Paul", "George", "Ringo"]
+    for (let name of names)
+    {
+        alert(`Hello, ${name}`)
+    }
+}
+
+
+//For Select Option
+{
+    const currencies = ["USD", "EUR", "GBP", "UAH"]
+    let   str = "<select>"
+    for (let currency of currencies){
+        str += '<option>'+currency+'</option>'
+    }
+    str+= "</select>"
+    document.write(str)
+}
+
+//For Table Horizontal
+{
+    const names = ["John", "Paul", "George", "Ringo"]
+    let   str = "<table border='1'>"
+    for (let namesTable of names){
+        str += '<td>'+namesTable+'</td>'
+    }
+    str+= "</table>"
+    document.write(str)
+}
+
+
+//For Table Vertical
+{
+    const names = ["John", "Paul", "George", "Ringo"]
+    let   str = "<table border='1'>"
+    for (let namesTable of names){
+        str += '<tr><td>'+namesTable+'</td></tr>'
+    }
+    str+= "</table>"
+    document.write(str)
+}
+
+//For Table Letters
+{
+    const currencies = ["USD", "EUR", "GBP", "UAH"]
+    let   str = "<table border='1'>"
+    for (let currency of currencies){ 
+        str += '<tr>'+currency+'</tr>'
+        console.log(currency)
+        for (let letter of currency){ 
+            str += '<td>'+letter+'</td>'
+            console.log(letter)
+        }
+    }
+    str+= "</table>"
+    document.write(str)
+}
+
+//For Multiply Table
+{
+    const arr = [[0,0,0,0,0],[0,1,2,3,4],[0,2,4,6,8],[0,3,6,9,12],[0,4,8,12,16]]
+    let   str = "<table border='1'>"
+    let   i   = 0
+    for (let currency of arr){
+        str += '<tr>'+currency+'</tr>'
+        console.log(currency)
+        for (let letter of currency){
+            str += '<td>'+letter+'</td>'
+            console.log(letter)
+        }
+    }
+    str+= "</table>"
+    document.write(str)
+}
+
+//Function Capitalize
+{
+    const capitalize = str => {
+        let result
+        result=str[0].toUpperCase()+str.toLowerCase().slice(1)
+        return result //именно этот код обеспечит возврат результата функции
+    }
+    console.log(capitalize("cANBerRa")) //Canberra
+}
+
+//Map Capitalize
+{
+    const capitalize = str => {
+        let result
+        result=str[0].toUpperCase()+str.toLowerCase().slice(1)
+        return result //именно этот код обеспечит возврат результата функции
+    }
+    str = prompt('Введите строку').split(' ')
+    arr = str.map(capitalize).join(' ')
+    alert(arr)
+}
+
+//Beep Lexics
+{
+    const motherWord = ['дурак']
+    const arr = prompt('Введите строку').split(' ')
+    let resultArr = arr.map(x => x===motherWord[0] ?x='BEEP':x=x).join(' ')//понимаю что это не решение, но ничего другого не придумал
+}
+
+
+//Reduce HTML
+{
+    const currencies = ["","USD", "EUR", "GBP", "UAH"]
+    let str          = "<select>"
+    str             += currencies.reduce( (a,b) => a+'<option>'+b+'</option>' )
+    str             += "</select>"
+    document.write(str)
+}
+
+
+
+
+

+ 186 - 0
Обьекты.js

@@ -0,0 +1,186 @@
+//Literals
+{
+    var ford = {
+        type:  "hybrid",
+        model: "fusion",
+        power: 180,
+        size: "4800/150/130",
+        fuel: "petrol",
+      };
+}
+
+
+//Literals expand
+var ford = {
+    type:  "hybrid",
+    [prompt('Введите название ключа')]: [prompt('Введите параметр')].join(' '),
+    power: 180,
+    size: "4800/150/130",
+    fuel: "petrol",
+  };
+
+
+//Literals copy
+let property = prompt('Введите свойство')
+const obj = {...ford}
+obj.type = property
+console.log(obj)
+
+//Html tree
+let body = {
+    tagName: 'body',
+    children: [{
+        tagName: 'div',
+        children: [{
+            tagName: 'span',
+            children: ["Enter a data please:"]
+        },
+        {
+            tagName: 'br',
+        },
+        {
+            tagName: 'input',
+            attrs: {
+                children: {
+                    type:'text',
+                    id:'name',
+                }
+            },
+        },
+        {
+            tagName: 'input',
+            attrs: {
+                children: {
+                    type:'text',
+                    id:'surname',
+                }
+            },
+        }]
+    },
+    {
+        tagName: 'div',
+        children: [{
+            tagName: 'button',
+            attrs: {
+                [attributes]: "ok",
+            },
+            children:['OK']
+        },
+        {
+            tagName: 'button',
+            attrs: {},
+        }]
+    }]
+    
+}
+body.children[1].children[1].children=["Cancel"];
+body.children[1].children[1].attrs.id= "cancel";
+
+
+//Parent
+body.children[0].parent = body;
+body.children[1].parent = body;
+body.children[0].children[0].parent = body.children[0];
+body.children[0].children[1].parent = body.children[0];
+body.children[0].children[2].parent = body.children[0];
+body.children[0].children[3].parent = body.children[0];
+body.children[1].children[0].parent = body.children[1];
+body.children[1].children[1].parent = body.children[1];
+
+//destruct array
+{
+    let arr = [1,2,3,4,5, "a", "b", "c"]
+    let [odd1,even1,odd2,even2,odd3,...arr2]=arr
+    console.log(odd1,even1,odd2,even2,odd3,arr2)//1 2 3 4 5 [ 'a', 'b', 'c' ]
+}
+//destruct string
+{
+    let arr = [1, "abc"]
+    let [number,arr2]=arr
+    let [s1,s2,s3]=arr2
+    console.log(number,s1,s2,s3)// 1 a b c
+}
+//destruct 2
+{
+    let obj = {
+        name: 'Ivan',
+        surname: 'Petrov',
+        children: [{name: 'Maria'}, {name: 'Nikolay'}]
+    }
+    let {children:[{name:name1},{name:name2}]}= obj
+    console.log(name1,name2)//Maria Nikolay
+}
+//destruct 3
+{
+    let arr = [1,2,3,4, 5,6,7,10]
+    let {0:a,1:b,length}= arr
+    console.log(a,b,length)//1 2 8
+}
+//Destructure и Change OK
+{
+    let attributes = prompt('Введите название атрибута')// это к заданию Change OK
+    let body = {
+        tagName: 'body',
+        children: [{
+            tagName: 'div',
+            children: [{
+                tagName: 'span',
+                children: ["Enter a data please:"]
+            },
+            {
+                tagName: 'br',
+            },
+            {
+                tagName: 'input',
+                attrs: {
+                    children: {
+                        type:'text',
+                        id:'name',
+                    }
+                },
+            },
+            {
+                tagName: 'input',
+                attrs: {
+                        type:'text',
+                        id:'surname',
+                },
+            }]
+        },
+        {
+            tagName: 'div',
+            children: [{
+                tagName: 'button',
+                attrs: {
+                    [attributes]: "ok",
+                },
+                children:['OK']
+            },
+            {
+                tagName: 'button',
+                children:["Cancel"],
+                attrs: {
+                    id: "cancel"
+                },
+            }]
+        }]
+        
+    }
+    let {children:[{children:[{children:[textSpan]},{},{},{attrs:{id:textSurname}}]},{children:[{},{children:[textCancel]}]}]}=body//это к заданию Destructure
+    console.log(textSpan,textCancel,textSurname)//Enter a data please: Cancel surname                                              //это к заданию Destructure
+    body.children[1].children[0].attrs.attributes= prompt('Введите значение атрибута');// это к заданию Change OK
+}
+
+
+//Copy delete
+{
+    let ford = {
+        type:  "hybrid",
+        model: "fusion",
+        power: 180,
+        size: "4800/150/130",
+        fuel: "petrol",
+      };
+      const obj= {...ford}
+      delete obj[prompt('Введите ключ для удаления')]
+}