Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // document.querySelector[All]
- // element.querySelector[All]
- // VD 1
- const array = document.querySelectorAll('div.vidu div.phantucon')
- for (const element of array) {
- console.log(element.textContent)
- }
- const array = document.querySelectorAll('div.vidu')
- for (const container of array) {
- const subset = container.querySelectorAll('div.phantucon')
- for (const element of subset) {
- console.log(element.textContent)
- }
- }
- // VD 2
- // SQL: FROM output SELECT x * x
- const output = input.map(x => x * x)
- const output = []
- for (const x of input) output.push(x * x)
- // VD 3
- // SQL: FROM output SELECT x WHERE x > 3
- const output = input.filter(x => x > 3)
- const output = []
- for (const x of input) if (x > 3) output.push(x)
- // VD 4
- const output = input.map(callback)
- const output = []
- for (const x of input) output.push(callback(x))
- function callback () {}
- // VD 5
- const output = input.reduce((sum, x) => sum + x, 0)
- let output = 0
- for (const x of input) output = output + x
- // VD 6
- const output = input.sort((a, b) => a < b)
- const output = Array.from(input)
- for (let i = 0; i != output.length - 1; ++i) {
- const a = input[i]
- const b = input[i + 1]
- if (a < b) {
- output[i + 1] = a
- output[i] = b
- }
- }
- // VD 7
- const output = input.reduce(callback, initial)
- let output = initial
- for (const x of input) output = callback(output, x)
- // VD 8
- array.sort(callback)
- // if callback(a, b) returns -1, -2, -3, ..., +∞ >>> a is placed before b
- // if callback(a, b) returns +1, +2, +3, ..., -∞ >>> b is placed before a
- // if callback(a, b) returns 0 >>> a and b are treated equal
- // VD 9 Chữ hoa, chữ thường
- 'abcDEFghiJKL'.toUpperCase() // => 'ABCDEFGHIJKL'
- 'abcDEFghiJKL'.toLowerCase() // => 'abcdefghijkl'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement