main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 cells = document.querySelectorAll('td');
  39. let rows = document.querySelectorAll('tr');
  40. function highlightRow (tr) {
  41. let row = tr.children;
  42. function highlightCell (td, tdCount) {
  43. td.onmouseover = function () {
  44. for (let column of rows) {
  45. column.children[tdCount].style.backgroundColor = '#bcf'
  46. column.children[tdCount].style.color = '#fff'
  47. }
  48. for (let rowCell of row) {
  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[tdCount].style.backgroundColor = ''
  58. column.children[tdCount].style.color = ''
  59. }
  60. for (let rowCell of row) {
  61. rowCell.style.backgroundColor = ''
  62. rowCell.style.color = ''
  63. }
  64. td.style.backgroundColor = ''
  65. td.style.color = ''
  66. }
  67. }
  68. return highlightCell;
  69. }
  70. for (let row of rows) {
  71. let highlightCell = highlightRow(row);
  72. let tdCounter = 0;
  73. for (let cell of row.children) {
  74. highlightCell(cell, tdCounter);
  75. tdCounter++
  76. }
  77. }
  78. //makeProfileTimer
  79. function makeProfileTimer () {
  80. let startTime = performance.now()
  81. function innerTimer () {
  82. let endTime = performance.now()
  83. let workTime = endTime - startTime;
  84. return workTime;
  85. }
  86. return innerTimer;
  87. }
  88. //makeSaver
  89. function makeSaver (func) {
  90. let result;
  91. function returnResult () {
  92. if (!result) {
  93. result = func()
  94. }
  95. return result;
  96. }
  97. return returnResult;
  98. }
  99. //Final Countdown
  100. function countdown (numb) {
  101. let counter = numb;
  102. let countdown = setTimeout(function showCountdown () {
  103. if (counter < 1) {
  104. console.log('Поехали!')
  105. return;
  106. }
  107. console.log(counter)
  108. counter--
  109. countdown = setTimeout(showCountdown, 1000)
  110. }, 1000)
  111. }
  112. //MyBind
  113. function myBind(functionToBind, context, args) {
  114. function boundFunction (...newArgs) {
  115. let commonArgs = []
  116. let functionResult
  117. let counter = 0
  118. for (let argument of args) {
  119. if (argument === undefined) {
  120. commonArgs.push(newArgs[counter])
  121. counter++
  122. } else {
  123. commonArgs.push(argument)
  124. }
  125. }
  126. if (context) {
  127. context.key = functionToBind
  128. functionResult = context.key(...commonArgs)
  129. delete context.key
  130. } else {
  131. functionResult = functionToBind(...commonArgs)
  132. }
  133. return functionResult
  134. }
  135. return boundFunction
  136. }