Explorar el Código

added HW9 done

makstravm hace 3 años
padre
commit
cb9318134a
Se han modificado 3 ficheros con 110 adiciones y 41 borrados
  1. 3 0
      .vscode/extensions.json
  2. 22 20
      HW8/main.js
  3. 85 21
      HW9/main.js

+ 3 - 0
.vscode/extensions.json

@@ -0,0 +1,3 @@
+{
+  "recommendations": []
+}

+ 22 - 20
HW8/main.js

@@ -4,47 +4,48 @@ for (let rowIndex = 0; rowIndex <= 10; rowIndex++) {
   rowIndex % 2 === 0 ? tr.className = "tr-odd" : tr.className = "tr-even"
   table.append(tr)
   if (rowIndex === 0) {
-    for (let k = 0; k <= 10; k++) {
+    for (let t = 0; t <= 10; t++) {
       let th = document.createElement('th')
       th.className = 'th'
-      th.append(k)
+      th.innerText = t
       tr.append(th)
     }
   } else {
     for (let colIndex = 0; colIndex <= 10; colIndex++) {
       let td = document.createElement('td')
-      td.onmouseover = function () {
-        let array = [...this.parentElement.parentElement.children]
+
+      // подсвечивает строку и столбец  до указаной клетки
+
+      function lightTd(e) {
+        let arrayParentChildren = [...this.parentElement.parentElement.children]
         for (let row = 0; row <= tr.rowIndex; row++) {
           for (let cell = 0; cell <= td.cellIndex; cell++) {
-            if (cell === td.cellIndex) {
-              [...array[row].children][cell].style.backgroundColor = '#fffbcc'
+            if (e.type === 'mousemove') {
+              if (cell === td.cellIndex) {
+                [...arrayParentChildren[row].children][cell].style.backgroundColor = '#9e90ff'
+              }
+              [...this.parentElement.children][cell].style.backgroundColor = '#9e90ff'
+              this.style.backgroundColor = 'red'
+            } else {
+              [...arrayParentChildren[row].children][cell].style.backgroundColor = ''
             }
-            [...this.parentElement.children][cell].style.backgroundColor = '#fffbcc'
-          }
-        }
-        this.style.backgroundColor = 'red'
-      }
-      td.onmouseout = function () {
-        this.style.backgroundColor = ''
-        let array = [...this.parentElement.parentElement.children]
-        for (let cell = 0; cell <= tr.rowIndex; cell++) {
-          for (let row = 0; row <= td.cellIndex; row++) {
-            [...array[cell].children][row].style.backgroundColor = ''
           }
         }
       }
+      td.onmousemove = lightTd
+      td.onmouseout = lightTd
+
       if (colIndex === 0) {
         let th = document.createElement('th')
         th.className = 'th'
-        th.append((rowIndex) * (colIndex + 1))
+        th.innerText = (rowIndex) * (colIndex + 1)
         tr.append(th)
       } else if (colIndex === rowIndex) {
         td.className = 'tdtd'
-        td.append((rowIndex) * (colIndex))
+        td.innerText = (rowIndex) * (colIndex)
         tr.append(td)
       } else {
-        td.append((rowIndex) * (colIndex))
+        td.innerText = (rowIndex) * (colIndex)
         tr.append(td)
       }
     }
@@ -53,6 +54,7 @@ for (let rowIndex = 0; rowIndex <= 10; rowIndex++) {
 root.append(table)
 
 
+
 plus.addEventListener('click', () => {
   result.value = +numOne.value + +numTwo.value
 })

+ 85 - 21
HW9/main.js

@@ -1,3 +1,4 @@
+// Таблица,  замыкание
 let table = document.createElement('table')
 for (let rowIndex = 0; rowIndex <= 10; rowIndex++) {
   let tr = document.createElement('tr')
@@ -7,41 +8,35 @@ for (let rowIndex = 0; rowIndex <= 10; rowIndex++) {
     for (let t = 0; t <= 10; t++) {
       let th = document.createElement('th')
       th.className = 'th'
-      th.append(t)
+      th.innerText = t
       tr.append(th)
     }
   } else {
     for (let colIndex = 0; colIndex <= 10; colIndex++) {
       let td = document.createElement('td')
-      function findChild(e) {
-        let arrayParentChildren = [...this.parentElement.parentElement.children]
-        for (let row = 0; row <= tr.rowIndex; row++) {
-          for (let cell = 0; cell <= td.cellIndex; cell++) {
-            if (e.type === 'mousemove') {
-              if (cell === td.cellIndex) {
-                [...arrayParentChildren[row].children][cell].style.backgroundColor = '#fffbcc'
-              }
-              [...this.parentElement.children][cell].style.backgroundColor = '#fffbcc'
-              this.style.backgroundColor = 'red'
-            } else {
-              [...arrayParentChildren[row].children][cell].style.backgroundColor = ''
-            }
-          }
-        }
+
+      td.onmousemove = function () {
+        [...tr.parentElement.children].map(t => t.children[colIndex].style.backgroundColor = '#9e90ff')
+        td.parentElement.style.backgroundColor = '#9e90ff';
+        td.style.backgroundColor = 'red'
+      }
+      td.onmouseout = function () {
+        [...tr.parentElement.children].map(t => t.children[colIndex].style.backgroundColor = '')
+        td.style.backgroundColor = ''
+        td.parentElement.style.backgroundColor = ''
       }
-      td.onmousemove = findChild
-      td.onmouseout = findChild
+
       if (colIndex === 0) {
         let th = document.createElement('th')
         th.className = 'th'
-        th.append((rowIndex) * (colIndex + 1))
+        th.innerText = (rowIndex) * (colIndex + 1)
         tr.append(th)
       } else if (colIndex === rowIndex) {
         td.className = 'tdtd'
-        td.append((rowIndex) * (colIndex))
+        td.innerText = (rowIndex) * (colIndex)
         tr.append(td)
       } else {
-        td.append((rowIndex) * (colIndex))
+        td.innerText = (rowIndex) * (colIndex)
         tr.append(td)
       }
     }
@@ -49,3 +44,72 @@ for (let rowIndex = 0; rowIndex <= 10; rowIndex++) {
 }
 root.append(table)
 
+//makeProfileTimer
+
+function makeProfileTimer() {
+  let t0 = performance.now();
+  return function () {
+    let t1 = performance.now();
+    return t1 - t0
+  }
+}
+
+let timer = makeProfileTimer()
+alert('Замеряем время работы этого alert')
+alert(timer())
+
+//makeSaver
+
+function makeSaver(param) {
+  let res;
+  let flag = false;
+  return function () {
+    debugger
+    flag ? res : (flag = true, res = param());
+  }
+};
+
+let saver = makeSaver(Math.random)
+let value1 = saver()
+let value2 = saver()
+console.log(value1 === value2);
+
+let saver2 = makeSaver(() => console.log('saved function called') || [null, undefined, false, '', 0, Math.random()][Math.ceil(Math.random() * 6)])
+let value3 = saver2()
+let value4 = saver2()
+console.log(value3 === value4);
+
+//Final Countdown
+
+(function () {
+  let seconds = 5
+  for (let i = 0; i <= seconds; i++) {
+    setTimeout(() => {
+      !seconds ? console.log('поехали!') : console.log(seconds--);
+    }, 1000 * i);
+  }
+}())
+
+//myBind
+
+function myBind(f, method, arr) {
+  return function (...params) {
+    let countIndex = 0
+    let newArr = arr.map(i => i !== undefined ? i : params[countIndex++])
+    return f.apply(method, newArr)
+  }
+}
+
+var pow5 = myBind(Math.pow, Math, [undefined, 5])
+pow5(2)
+
+var cube = myBind(Math.pow, Math, [undefined, 3])
+cube(3)
+
+var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5, undefined, 8, undefined, 9])
+chessMin(-1, -5, 3, 15)
+
+var zeroPrompt = myBind(prompt, window, [undefined, "0"]) 
+var someNumber = zeroPrompt("Введите число")
+
+myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a', 'c', 'd') === 'abcdef'