main.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //Сама таблица Пифагора, такая же как и в домашке раньше
  2. let multiplyTable = []
  3. for (let i = 0; i <=10; i++) {
  4. multiplyTable[i] = []
  5. for (let j = 0; j <=10; j++) {
  6. multiplyTable[i][j] = i * j
  7. }
  8. }
  9. let tableContainer = document.querySelector('.multipleTable')
  10. let table = document.createElement('table')
  11. table.border = "1"
  12. for (let i = 0; i < multiplyTable.length; i++) {
  13. let row = document.createElement('tr')
  14. if (i == 0) {
  15. let cell = document.createElement ('td')
  16. cell.innerHTML = '&#9959;'
  17. row.appendChild(cell)
  18. } else {
  19. let cell = document.createElement('td')
  20. cell.innerText = i
  21. row.appendChild(cell)
  22. }
  23. for (let j = 1; j < multiplyTable[i].length; j++) {
  24. if (i == 0) {
  25. let cell = document.createElement('td')
  26. cell.innerText = multiplyTable[1][j]
  27. row.appendChild(cell)
  28. } else {
  29. let cell = document.createElement('td')
  30. cell.innerText = multiplyTable[i][j]
  31. row.appendChild(cell)
  32. }
  33. }
  34. table.appendChild(row)
  35. }
  36. tableContainer.appendChild(table)
  37. //подсветка строки и столбца с замыканиями
  38. let rows = document.querySelectorAll('tr');
  39. for (let tr of rows) {
  40. let tdCounter = 0;
  41. for (let td of tr.children) {
  42. let tdCounterToRemember = tdCounter;
  43. td.onmouseover = function () {
  44. for (let column of rows) {
  45. column.children[tdCounterToRemember].style.backgroundColor = '#bcf'
  46. column.children[tdCounterToRemember].style.color = '#fff'
  47. }
  48. for (let rowCell of tr.children) {
  49. rowCell.style.backgroundColor = '#bcf'
  50. rowCell.style.color = '#fff'
  51. }
  52. td.style.backgroundColor = '#6dd'
  53. td.style.color = '#fff'
  54. }
  55. td.onmouseout = function () {
  56. for (let column of rows) {
  57. column.children[tdCounterToRemember].style.backgroundColor = ''
  58. column.children[tdCounterToRemember].style.color = ''
  59. }
  60. for (let rowCell of tr.children) {
  61. rowCell.style.backgroundColor = ''
  62. rowCell.style.color = ''
  63. }
  64. td.style.backgroundColor = ''
  65. td.style.color = ''
  66. }
  67. tdCounter++
  68. }
  69. }
  70. //makeProfileTimer
  71. function makeProfileTimer () {
  72. let startTime = performance.now()
  73. function innerTimer () {
  74. let endTime = performance.now()
  75. let workTime = endTime - startTime;
  76. return workTime;
  77. }
  78. return innerTimer;
  79. }
  80. //makeSaver
  81. function makeSaver (func) {
  82. let result;
  83. function returnResult () {
  84. if (result === undefined) {
  85. result = func()
  86. }
  87. return result;
  88. }
  89. return returnResult;
  90. }
  91. //Final Countdown
  92. function countdown (numb) {
  93. let counter = numb;
  94. let countdown = setTimeout(function showCountdown () {
  95. if (counter < 1) {
  96. console.log('Поехали!')
  97. return;
  98. }
  99. console.log(counter)
  100. counter--
  101. countdown = setTimeout(showCountdown, 1000)
  102. }, 1000)
  103. }
  104. //or
  105. // let n = 5
  106. // for (let i = n, j = 1; i >= 0; i--, j++) {
  107. // if (i === 0) {
  108. // setTimeout(console.log, 1000 * j, 'Поехали!')
  109. // break
  110. // }
  111. // setTimeout(console.log, 1000 * j, i)
  112. // }
  113. //MyBind
  114. function myBind(functionToBind, context, args) {
  115. function boundFunction (...newArgs) {
  116. let commonArgs = []
  117. let functionResult
  118. let counter = 0
  119. for (let argument of args) {
  120. if (argument === undefined) {
  121. commonArgs.push(newArgs[counter])
  122. counter++
  123. } else {
  124. commonArgs.push(argument)
  125. }
  126. }
  127. if (context) {
  128. functionResult = functionToBind.call(context, ...commonArgs)
  129. } else {
  130. functionResult = functionToBind(...commonArgs)
  131. }
  132. return functionResult
  133. }
  134. return boundFunction
  135. }