Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. <script>
  2.  
  3. const ArrayHouse = [
  4. {
  5. name: 'house1',
  6. rooms: [
  7. {
  8. number: 3,
  9. chairs: [
  10. {
  11. color: 'red',
  12. height: 10,
  13. width: 45
  14. },
  15. {
  16. color: 'red',
  17. height: 10,
  18. width: 45
  19. },
  20. {
  21. color: 'red',
  22. height: 10,
  23. width: 45
  24. }
  25. ]
  26. },
  27. {
  28. number: 1,
  29. chairs: [
  30. {
  31. color: 'green',
  32. height: 10,
  33. width: 45
  34. },
  35. {
  36. color: 'black',
  37. height: 10,
  38. width: 45
  39. },
  40. {
  41. color: 'violet',
  42. height: 10,
  43. width: 45
  44. }
  45. ]
  46. }
  47. ]
  48. },
  49. {
  50. name: 'house2',
  51. rooms: [
  52. {
  53. number: 3,
  54. chairs: [
  55. {
  56. color: 'red',
  57. height: 10,
  58. width: 45
  59. },
  60. {
  61. color: 'red',
  62. height: 10,
  63. width: 45
  64. },
  65. {
  66. color: 'red',
  67. height: 10,
  68. width: 45
  69. }
  70. ]
  71. },
  72. {
  73. number: 1,
  74. chairs: [
  75. {
  76. color: 'green',
  77. height: 10,
  78. width: 45
  79. },
  80. {
  81. color: 'black',
  82. height: 10,
  83. width: 45
  84. },
  85. {
  86. color: 'violet',
  87. height: 10,
  88. width: 45
  89. }
  90. ]
  91. },
  92. {
  93. number: 15,
  94. chairs: [
  95. {
  96. color: 'green',
  97. height: 102,
  98. width: 45
  99. },
  100. {
  101. color: 'white',
  102. height: 110,
  103. width: 45
  104. },
  105. {
  106. color: 'violet',
  107. height: 150,
  108. width: 45
  109. }
  110. ]
  111. }
  112. ]
  113. }
  114. ]
  115.  
  116. class HouseContext {
  117.  
  118. constructor() {
  119. console.log(this.getHouseByName('house1'));
  120. this.addHouse({
  121. name: 'addHouse',
  122. rooms: []
  123. });
  124. console.log(ArrayHouse);
  125.  
  126. console.log(this.getRoomBuNumber('house2', 1));
  127.  
  128. this.addRoom('addHouse', {
  129. number: 228,
  130. chairs:[]
  131. });
  132.  
  133. console.log(ArrayHouse);
  134. }
  135.  
  136. getHouseByName(name) {
  137. return ArrayHouse.find(v => v.name == name);
  138. }
  139.  
  140. addHouse(house) {
  141. ArrayHouse.push(house);
  142. }
  143.  
  144. getRoomBuNumber(houseName, roomNumber) {
  145. return ArrayHouse.find(v => v.name == houseName).rooms.find(v => v.number == roomNumber);
  146. }
  147.  
  148. addRoom(houseName, room) {
  149. ArrayHouse.find(v => v.name == houseName).rooms.push(room);
  150. }
  151. }
  152.  
  153. new HouseContext();
  154.  
  155.  
  156. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement