123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //Сама таблица Пифагора, такая же как и в домашке раньше
- let multiplyTable = []
- for (let i = 0; i <=10; i++) {
- multiplyTable[i] = []
- for (let j = 0; j <=10; j++) {
- multiplyTable[i][j] = i * j
- }
- }
- let tableContainer = document.querySelector('.multipleTable')
- let table = document.createElement('table')
- table.border = "1"
- for (let i = 0; i < multiplyTable.length; i++) {
- let row = document.createElement('tr')
- if (i == 0) {
- let cell = document.createElement ('td')
- cell.innerHTML = '⛧'
- row.appendChild(cell)
- } else {
- let cell = document.createElement('td')
- cell.innerText = i
- row.appendChild(cell)
- }
- for (let j = 1; j < multiplyTable[i].length; j++) {
- if (i == 0) {
- let cell = document.createElement('td')
- cell.innerText = multiplyTable[1][j]
- row.appendChild(cell)
- } else {
- let cell = document.createElement('td')
- cell.innerText = multiplyTable[i][j]
- row.appendChild(cell)
- }
- }
-
- table.appendChild(row)
- }
- tableContainer.appendChild(table)
- //подсветка строки и столбца с замыканиями
- let rows = document.querySelectorAll('tr');
- for (let tr of rows) {
- let tdCounter = 0;
- for (let td of tr.children) {
- let tdCounterToRemember = tdCounter;
- td.onmouseover = function () {
- for (let column of rows) {
- column.children[tdCounterToRemember].style.backgroundColor = '#bcf'
- column.children[tdCounterToRemember].style.color = '#fff'
- }
- for (let rowCell of tr.children) {
- rowCell.style.backgroundColor = '#bcf'
- rowCell.style.color = '#fff'
- }
- td.style.backgroundColor = '#6dd'
- td.style.color = '#fff'
- }
- td.onmouseout = function () {
- for (let column of rows) {
- column.children[tdCounterToRemember].style.backgroundColor = ''
- column.children[tdCounterToRemember].style.color = ''
- }
- for (let rowCell of tr.children) {
- rowCell.style.backgroundColor = ''
- rowCell.style.color = ''
- }
- td.style.backgroundColor = ''
- td.style.color = ''
- }
- tdCounter++
- }
- }
- //makeProfileTimer
- function makeProfileTimer () {
- let startTime = performance.now()
- function innerTimer () {
- let endTime = performance.now()
- let workTime = endTime - startTime;
- return workTime;
- }
- return innerTimer;
- }
- //makeSaver
- function makeSaver (func) {
- let result;
- function returnResult () {
- if (result === undefined) {
- result = func()
- }
- return result;
- }
- return returnResult;
- }
- //Final Countdown
- function countdown (numb) {
- let counter = numb;
- let countdown = setTimeout(function showCountdown () {
- if (counter < 1) {
- console.log('Поехали!')
- return;
- }
- console.log(counter)
- counter--
- countdown = setTimeout(showCountdown, 1000)
- }, 1000)
- }
- //or
- // let n = 5
- // for (let i = n, j = 1; i >= 0; i--, j++) {
- // if (i === 0) {
- // setTimeout(console.log, 1000 * j, 'Поехали!')
- // break
- // }
- // setTimeout(console.log, 1000 * j, i)
- // }
- //MyBind
- function myBind(functionToBind, context, args) {
- function boundFunction (...newArgs) {
- let commonArgs = []
- let functionResult
- let counter = 0
- for (let argument of args) {
- if (argument === undefined) {
- commonArgs.push(newArgs[counter])
- counter++
- } else {
- commonArgs.push(argument)
- }
- }
- if (context) {
- functionResult = functionToBind.call(context, ...commonArgs)
- } else {
- functionResult = functionToBind(...commonArgs)
- }
- return functionResult
- }
- return boundFunction
- }
|