-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplaceTextInDom.js
More file actions
80 lines (52 loc) · 1.46 KB
/
Copy pathreplaceTextInDom.js
File metadata and controls
80 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function replaceText(query, replacement, node) {
if(!node || !query || typeof replacement !== 'string') return;
if(node.nodeType === Node.TEXT_NODE) {
console.log(node.nodeValue);
node.nodeValue = node.nodeValue.replaceAll(new RegExp(query, 'g'), replacement);
console.log(node.nodeValue);
} else {
Array.from(node.childNodes).forEach(child => { // use for loop to save space.
replaceText(query, replacement, child);
})
}
}
Q1. implement EventManager
addEventListener
removeEventListener
dispatchEvent
EventManager.addEventListener('click', () => {} )
// follow ups
1. Memory leak prevention
2. runtime optimizn (use set?)
3. map vs object
4.
Q2. find nextSibling of given tree.
div
/ | \
div -> div -> div
/ \ | |
a->p -> a -> p
| | |
a->span -> button
div
/ | \
div -> div -> div
/ \ | |
a->p -> a -> p
| |
a -> button
$('button')
.css('color', '#fff')
.css('backgroundColor', '#000')
.css('fontWeight', 'bold')
implement
+ communications
+ thought process
+ able to pick up hints
- object vs map, not certain
- use examples
- outline your approach and discuss w/ interviewer
- confused w/ simple methods, maybe better to brush up,
- uncertain about set iteration order
- minor mistakes - syntax error, == instead of ===, bugs.
- keep track of Time, focus on writing code vs long discussions (unless prompted by interviewer)