Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. # CSS
  2.  
  3. 1. What is CSS BEM?
  4.  
  5. CSS的一種命名規則, 由區塊(Block)、 元素(Element) 與修飾詞(Modifier) 組合而成,
  6. 元素帶有雙底線前墜, 修飾詞帶有雙減號前墜, 藉由這種命名規則來增加使用的方便度
  7.  
  8. 2. What is the difference between em and rem units?
  9.  
  10. em: 為字大小的長度, 會受到上下文的影響, 若有改變過字體大小則會跟著改變em長度
  11. rem: 為html標籤的字體大小長度, 不受上下文影響
  12.  
  13. 3. Using flexbox, create a 3-column layout where each column takes up a col-{n} / 12 ratio of the container.
  14.  
  15. <div class="row">
  16. <div class="col-2"></div>
  17. <div class="col-7"></div>
  18. <div class="col-3"></div>
  19. </div>
  20.  
  21. .row {
  22. display: flex;
  23. }
  24.  
  25. .col - 2 {
  26. flex: 2;
  27. }
  28.  
  29. .col - 3 {
  30. flex: 2;
  31. }
  32.  
  33. .col - 7 {
  34. flex: 2;
  35. }
  36.  
  37. -------------------------------------------------
  38.  
  39. # HTML
  40.  
  41. 1. What is HTML5 Web Storage? Explain localStorage and sessionStorage.
  42.  
  43. Web Storage 為一種儲存於客戶端的方法, 分為localStorage與sessionStorage。 不同於cookie, 此方法不會跟隨請求送出而浪費頻寬。
  44.  
  45. localStorage: 沒有到期限制, 就算關閉瀏覽器還是會存在, 不同分頁間是共用的。
  46. sessionStorage: 當瀏覽器被關閉, 資料就會消失。
  47.  
  48. 2. What’s the difference between a block-level element and an inline element?
  49.  
  50. block元素: 元素從新的一行開始, 不論寬度, 都會占用全部寬度
  51. inline元素: 行內元素, 占用寬度為內部元素寬度, 不會造成段行或改變配置
  52.  
  53. -------------------------------------------------
  54.  
  55. # Javascript
  56.  
  57. 1. What are the differences between var, let and const?
  58.  
  59. const: 作用域為區塊,在區塊內不可重複宣告, 沒有自動提升特性, 不可重複賦值, 宣告時必須賦值, 首次宣告後不能更動其定址。
  60. let: 作用域為區塊,在區塊內不可重複宣告, 沒有自動提升特性, 可以重複賦值。
  61. var: 作用域為函式內 重複宣告會蓋過前面的值, 有自動提升特性, 在賦值前呼叫為undefined。
  62.  
  63. 2. What is the difference between the array methods map() and forEach()?
  64.  
  65. map: 無副作用, 迴圈循環函式, 次數為陣列的寬, 回傳新的陣列, 陣列內容為函式回傳值的集合。
  66. forEach: 無副作用, 迴圈循環函式, 次數為陣列的寬度。
  67.  
  68. 3. Create a function batches that returns the maximum number of whole batches that can be cooked from a recipe.
  69.  
  70. /**
  71. It accepts two objects as arguments: the first object is the recipe
  72. for the food, while the second object is the available ingredients.
  73. Each ingredient's value is number representing how many units there are.
  74. `batches(recipe, available)`
  75. */
  76. // 0 batches can be made
  77. batches(
  78. { milk: 100, butter: 50, flour: 5 },
  79. { milk: 132, butter: 48, flour: 51 }
  80. )
  81. batches(
  82. { milk: 100, flour: 4, sugar: 10, butter: 5 },
  83. { milk: 1288, flour: 9, sugar: 95 }
  84. )
  85.  
  86. // 1 batch can be made
  87. batches(
  88. { milk: 100, butter: 50, cheese: 10 },
  89. { milk: 198, butter: 52, cheese: 10 }
  90. )
  91.  
  92. // 2 batches can be made
  93. batches(
  94. { milk: 2, sugar: 40, butter: 20 },
  95. { milk: 5, sugar: 120, butter: 500 }
  96. )
  97.  
  98. function batches(recipe, available) {
  99. let count = -1;
  100. Object.keys(recipe).forEach((index) => {
  101. const thisCount = available[index] ? Math.floor(available[index] / recipe[index]) : 0;
  102. if (count === -1) {
  103. count = thisCount;
  104. } else if (count !== 0) {
  105. count = Math.min(thisCount, count);
  106. }
  107. });
  108. return count;
  109. }
  110.  
  111. 4. Create a function pipe that performs left-to-right function composition by returning a function that accepts one argument.
  112.  
  113. const square = v => v * v
  114. const double = v => v * 2
  115. const addOne = v => v + 1
  116. const res = pipe(square, double, addOne)
  117. res(3) // 19; addOne(double(square(3)))
  118.  
  119. function pipe() {
  120. const arg = arguments;
  121. return function (value) {
  122. let sum = 0;
  123. const length = arg.length;
  124. for (let i = 0; i < length; i++) {
  125. sum = arg[i](i === 0 ? value : sum);
  126. }
  127. return sum;
  128. };
  129. }
  130.  
  131. 5. Create a function to handler Array Object data
  132.  
  133. input origin Data:
  134. const authors = [
  135.  
  136. {
  137. name: ‘張曼娟’,
  138. id: ‘a001’,
  139. books: [{
  140. name: ‘人間好時節’,
  141. id: ‘a1b001’,
  142. },
  143. {
  144. name: ‘時間的旅人’,
  145. id: ‘a1b002’,
  146. },
  147. ],
  148. }, {
  149. name: ‘瑞. 達利歐’,
  150. id: ‘a002’,
  151. books: [{
  152. name: ‘原則: 生活和工作’,
  153. id: ‘a2b001’,
  154. }, ],
  155. },
  156.  
  157. ];
  158.  
  159. output flat Data:
  160. const books = [
  161.  
  162. {
  163. author: ‘張曼娟’,
  164. authorId: ‘a001’,
  165. book: ‘人間好時節’,
  166. bookId: ‘a1b001’,
  167. }, ….other book
  168.  
  169. ];
  170.  
  171. function getBooks(authors = []) {
  172. return authors.reduce((books, authorValue) => {
  173. let book = [];
  174. if (authorValue.books) {
  175. book = authorValue.books.map((authorBooks) => ({
  176. author: authorValue.name,
  177. authorId: authorValue.id,
  178. book: authorBooks.name,
  179. bookId: authorBooks.id,
  180. }));
  181. }
  182. return books.concat(...book);
  183. }, [])
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement