Browse Source

HW <8> done

Vadym Shakhmatenko 1 year ago
parent
commit
46d6e26629
4 changed files with 142 additions and 36 deletions
  1. 1 11
      HomeWork4/index.html
  2. 18 17
      HomeWork5/index.html
  3. 6 8
      Homework7/index.html
  4. 117 0
      Homework8/index.html

+ 1 - 11
HomeWork4/index.html

@@ -222,17 +222,7 @@
         }
 
 
-        // matrix to html table
-        let str = '<table border = "1">';
-        for(let i = 0; i <= 0; i++) {
-            str += '<tr> <td> FIRST </td>'
-            for(let j = 0; j <= 0; j++) {
-                str += '<td> SECOND </td> </tr>'
-            }
-        }
-        str += "</table>"
-        document.write(str)
-
+      
     
 
 

+ 18 - 17
HomeWork5/index.html

@@ -46,7 +46,7 @@
         }
 
         //array of persons
-        let persons = [];
+        var persons = [];
         persons.push(a)
         persons.push(b)
         persons.push(c)
@@ -87,26 +87,27 @@
         console.log(persons)
 
         //html
-        var str = "<table border='1'>"
-        for (let i = 0;i < 4;i++){
-            for (let key in persons[i]) {
-                    str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
-                 }
+        let str = '<table border = "1">'
+        for (let key in persons) {
+            str +=
+                `<tr> <td> name </td> <td> ${persons[key].name} </td> <td> surname </td> <td> ${persons[key].surname} </td> </tr> \n`;
         }
         str += "</table>"
+
         console.log(str)
         document.write(str)
 
         //HTML optional fields  ++++++  //HTML tr color
-        var str = "<table border='1'>"
-        for (let i = 0;i < persons.length;i++){
-            for (let key in persons[i]) {
-                str += `<tr style="color:#ff0000"><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
-                }
+        let str2 = '<table border = "1">'
+        for (let keys of persons){
+             str2 +=
+                `<tr> <td> ${keys} </td> <td> </td></tr> \n`;
         }
-        str += "</table>"
-        console.log(str)
-        document.write(str)
+           
+        str2 += "</table>"
+
+        console.log(str2)
+        document.write(str2)
 
         //destruct array
         let arr = [1,2,3,4,5, "a", "b","c"]
@@ -126,9 +127,9 @@
                 children: [{ name: name1 }, { name: name2 }],
             } = obj;
 
-        // destruct 3 
-        let arr3 = [1,2,3,4, 5,6,7,10]
-        let [a ,b , {length = arr3.length}] = arr
+        //destruct 3 
+        // let arr3 = [1,2,3,4, 5,6,7,10]
+        // let [a ,b , {length = arr3.length}] = arr
 
 
     </script>

+ 6 - 8
Homework7/index.html

@@ -50,20 +50,18 @@
           table.onmouseover = (event) => light(event, 'silver');
           table.onmouseout = (event) => light(event, '');  
 
-
     //Calc
         const numberOne = document.getElementById('firstNum')
         const numberSecond = document.getElementById('secondNum')
-    calc.onclick = function(){
-        var result = document.getElementById('result')
-      } 
-      
+
+    calc.onclick = (result) =>  document.getElementById('result')
+    
     //Calc Live
-    function calc() {
-      result.value = ((+numberOne.value) * (+numberSecond.value)) 
-    }
+    calc = () => result.value = ((+numberOne.value) * (+numberSecond.value)) 
+    
         numberOne.oninput = calc
         numberSecond.oninput = calc
+        
 </script>
     
 </body>

+ 117 - 0
Homework8/index.html

@@ -0,0 +1,117 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+//ES6 done hw7
+
+//sort
+            var persons = [
+                    {name: "Иван", age: 17},
+                    {name: "Мария", age: 35},
+                    {name: "Алексей", age: 73},
+                    {name: "Яков", age: 12},
+            ]
+
+            function sort(array, keys, boolean){
+                    array.sort(sorting)   
+                function sorting(a, b){
+                            return (boolean) ? (a[keys] < b[keys]) : (b[keys] < a[keys]);
+            }
+                return array;
+            }
+
+            console.log(sort(persons, "age"));
+            // console.log(sort(persons, "name", false));
+            // console.log(sort(persons, "age",true));
+
+
+
+//array map
+            var array = ["1", {}, null, undefined, "500", 700]
+            var result  = array.map(function(item) {
+                var number = parseInt(item);
+                return isNaN(number)? item : number;
+            });
+
+            console.log(result);
+//array reduce
+            var arr = ["0", 5, 3, "string", null]
+            function reducing(total, i){
+                if (!isNaN(i) && i != 0  && isFinite(i) && i != null){
+                return total*=i
+                }
+                return total;
+            };
+            var result2 = arr.reduce(reducing, 1)
+
+            console.log( result2 )
+
+//object filter 
+        var phone = {
+                brand: "meizu",
+                model: "m2",
+                ram: 2,
+                color: "black",
+        };
+
+ console.log(filter(phone,(key,value) => key == "color" || value == 2));
+
+ 
+        function filter(object ,key , value){
+            var result = {};
+            for(var key in object){
+                for(var value in object){
+                    if(object[key] == 2) result[key] = object[key];
+                    if(value == "color") result[value] = object[value];
+                }
+            }
+            return result;
+        }
+
+
+
+
+
+//object map 
+               map({name: "Иван", age: 17},function(key,value){
+                var result = {};
+                result[key+"_"] = value + "$";                                             
+                return result;                                   
+            }) 
+            //должен вернуть {name_: "Иван$", age_:"17$"}                                   
+            function map(object, funct){                                   
+                for(key in object){
+                funct(object, key, object[key]);
+                    delete object[key];
+            }
+                return object;
+            }
+
+            function check(object, key, value){
+                object[key + "_"] = value + "$";
+                return object;
+            }
+
+            console.log(map({name: "Иван", age: 17}, check)) 
+
+
+//Рекурсия +++++++++++
+        function recurse(min , step , max){
+            if (max <= 0) return 0;
+            return min + recurse(min + step, step ,max -1)
+        }
+
+        console.log(recurse(5,10,15) + " = Сумма арифметической прогрессии Sn")
+
+
+
+    </script>
+    
+</body>
+</html>