Daria преди 4 години
родител
ревизия
6d2a939021
променени са 4 файла, в които са добавени 228 реда и са изтрити 0 реда
  1. 98 0
      js_homework_07/index.html
  2. 2 0
      js_homework_07/main.js
  3. 12 0
      js_homework_08/index.html
  4. 116 0
      js_homework_08/main.js

+ 98 - 0
js_homework_07/index.html

@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="main.js"></script>
+</head>
+<body>  
+    <style>
+        .table {
+        padding: 15px;
+        border: 1px solid #e9c6c6;
+        border-radius: 4px;
+        color: #4e4339;
+        background-color: #f8ffcd;
+        text-align: center;
+        }
+        .td{
+            height: 25px;
+            width: 25px;
+            text-align: center;
+        }
+    </style>
+    <script>
+        let table = document.createElement('table');
+        table.setAttribute('border','1')
+        table.className = "table";
+        
+        document.body.append(table)
+        table.setAttribute("align", "center");
+
+        for(let y = 0; y<10;y++){
+            let tr = document.createElement('tr')
+            table.append(tr)
+            for(let x = 0; x<10;x++){
+                let td = document.createElement('td')
+                table.append(td)
+
+                let temp = x*y;
+                if(x===0){
+                    temp = y
+                }
+                else if( y===0){
+                    temp = x
+                }
+                td.innerText = temp
+                td.className = "td";        
+                // td.onmousemove = function () {
+                // this.style.background = "yellow";
+                // }
+
+                // td.onmouseout = function () {
+                // this.style.background = "none";
+                // }
+
+
+
+
+
+
+                // td.onmousemove = function () {
+
+                // for (let item of this.parentElement.children) {
+                //     item.style.background = "yellowgreen";
+                // }
+                // for (let item of this.parentElement.parentElement.children) {
+                //     for (let item2 of item.children) {
+                //         if (item2.cellIndex === this.cellIndex) {
+                //             item2.style.background = "yellowgreen";
+                //         }
+                //     }
+                // }
+                // }
+                // td.onmouseout = function () {
+
+                // for (let item of this.parentElement.children) {
+                //     item.style.background = "none";
+                // }
+                // for (let item of this.parentElement.parentElement.children) {
+                //     for (let item2 of item.children) {
+                //         if (item2.cellIndex === this.cellIndex) {
+                //             item2.style.background = "none";
+                //         }
+                //     }
+                // }
+                // }
+                //ХЗ ЧЕГО НЕ РАБОТАЕТ
+
+
+
+
+            }
+        }
+    </script>
+ 
+</body>
+</html>

+ 2 - 0
js_homework_07/main.js

@@ -0,0 +1,2 @@
+
+

+ 12 - 0
js_homework_08/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="main.js"></script>
+</head>
+<body>
+    
+</body>
+</html>

+ 116 - 0
js_homework_08/main.js

@@ -0,0 +1,116 @@
+// sort
+// Сделайте обобщенную функцию сортировки массива
+var persons = [{
+    name: "Иван",
+    age: 17
+},
+{
+    name: "Мария",
+    age: 35
+},
+{
+    name: "Алексей",
+    age: 73
+},
+{
+    name: "Яков",
+    age: 12
+},
+]
+
+function sort(array, key, increase = true) {
+if (increase) {
+    array.sort(function (a, b) {
+        if (a[key] > b[key]) {
+            return 1;
+        }
+        if (a[key] < b[key]) {
+            return -1;
+        }
+        return 0;
+    });
+} else {
+    array.sort(function (a, b) {
+        if (a[key] < b[key]) {
+            return 1;
+        }
+        if (a[key] > b[key]) {
+            return -1;
+        }
+        return 0;
+    });
+}
+return array;
+};
+
+// array map
+// Используя Array.map приведите все строки в массиве к числу. Элементы других типов оставьте как есть
+
+let arrayMap = ["1", {}, null, undefined, "500", 700];
+
+let arrayMap2 = arrayMap.map((item) => {
+    if (typeof item == "string") return isNaN(parseInt(item, 10)) ? item : parseInt(item, 10);
+    return item;
+});
+
+// array reduce
+// Получите произведение всех чисел в массиве, используя Array.reduce. Не обрабатывайте типы данных, не являющиеся числом.
+
+let arrayReduce = ["0", 5, 3, "string", null];
+
+let arrPow = arrayReduce.reduce((a, b) => (typeof b == "number" ? a * b : a), 1);
+
+console.log(arrPow);
+
+// object filter
+// Напишите свою реализацию Array.filter для объектов
+
+var phone = {
+    brand: "meizu",
+    model: "m2",
+    ram: 2,
+    color: "black",
+};
+
+function objFilter(obj) {
+    let obj2 = {};
+    for (let key in obj) {
+        if (key == "color" || obj[key] == 2) {
+            obj2[key] = obj[key];
+        }
+    }
+    return obj2;
+}
+
+console.log(objFilter(phone));
+
+// object map
+// Напишите свою реализацию Array.map для объектов
+
+let object = {
+    name: "Иван",
+    age: 17
+};
+
+function map(obj) {
+    let temp = {};
+    for (let i in obj) {
+        temp[i + '_'] = i + '$';
+    }
+    return temp;
+}
+
+console.log(map(object))
+
+// Sum
+// Напишите функцию, который будет считать сумму арифметической прогрессии рекурсивно
+
+
+function progression( num, increment, rows) {
+    if (rows <= 1) {
+        return num;
+    }
+    return num + progression(num + increment, increment, rows - 1)
+}
+
+console.log(progression( 1,4, 8));