Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // document.querySelector[All]
  2. // element.querySelector[All]
  3.  
  4. // VD 1
  5.  
  6. const array = document.querySelectorAll('div.vidu div.phantucon')
  7. for (const element of array) {
  8. console.log(element.textContent)
  9. }
  10.  
  11. const array = document.querySelectorAll('div.vidu')
  12. for (const container of array) {
  13. const subset = container.querySelectorAll('div.phantucon')
  14. for (const element of subset) {
  15. console.log(element.textContent)
  16. }
  17. }
  18.  
  19. // VD 2
  20. // SQL: FROM output SELECT x * x
  21.  
  22. const output = input.map(x => x * x)
  23.  
  24. const output = []
  25. for (const x of input) output.push(x * x)
  26.  
  27. // VD 3
  28. // SQL: FROM output SELECT x WHERE x > 3
  29.  
  30. const output = input.filter(x => x > 3)
  31.  
  32. const output = []
  33. for (const x of input) if (x > 3) output.push(x)
  34.  
  35. // VD 4
  36.  
  37. const output = input.map(callback)
  38.  
  39. const output = []
  40. for (const x of input) output.push(callback(x))
  41.  
  42. function callback () {}
  43.  
  44. // VD 5
  45.  
  46. const output = input.reduce((sum, x) => sum + x, 0)
  47.  
  48. let output = 0
  49. for (const x of input) output = output + x
  50.  
  51. // VD 6
  52.  
  53. const output = input.sort((a, b) => a < b)
  54.  
  55. const output = Array.from(input)
  56. for (let i = 0; i != output.length - 1; ++i) {
  57. const a = input[i]
  58. const b = input[i + 1]
  59. if (a < b) {
  60. output[i + 1] = a
  61. output[i] = b
  62. }
  63. }
  64.  
  65. // VD 7
  66.  
  67. const output = input.reduce(callback, initial)
  68.  
  69. let output = initial
  70. for (const x of input) output = callback(output, x)
  71.  
  72. // VD 8
  73.  
  74. array.sort(callback)
  75. // if callback(a, b) returns -1, -2, -3, ..., +∞ >>> a is placed before b
  76. // if callback(a, b) returns +1, +2, +3, ..., -∞ >>> b is placed before a
  77. // if callback(a, b) returns 0 >>> a and b are treated equal
  78.  
  79. // VD 9 Chữ hoa, chữ thường
  80.  
  81. 'abcDEFghiJKL'.toUpperCase() // => 'ABCDEFGHIJKL'
  82. 'abcDEFghiJKL'.toLowerCase() // => 'abcdefghijkl'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement