File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 66
771 . [ Show the different ways of selecting an element from DOM] ( #Q1 )
881 . [ Show the ways to loop over the Nodelist obtained after querying for the elements] ( #Q2 )
9+ 3 . [ Design and Implement a Node Store, which supports DOM element as key] ( #Q3 )
910
1011---
1112
@@ -43,4 +44,50 @@ Note goes here
4344
4445<br />
4546
47+
48+ #### Q3
49+ ### Design and Implement a Node Store, which supports DOM element as key
50+
51+ - Implement it without using inbuilt Map
52+ - Can you do it in O(1) Time complexity?
53+
54+ ``` js
55+ class NodeStore {
56+
57+ constructor () {
58+ this .store = {};
59+ }
60+ /**
61+ * @param {Node} node
62+ * @param {any} value
63+ */
64+ set (node , value ) {
65+ node .__nodeIdentifier__ = Symbol ();
66+ this .store [node .__nodeIdentifier__ ] = value
67+ }
68+ /**
69+ * @param {Node} node
70+ * @return {any}
71+ */
72+ get (node ) {
73+ return this .store [node .__nodeIdentifier__ ];
74+ }
75+
76+ /**
77+ * @param {Node} node
78+ * @return {Boolean}
79+ */
80+ has (node ) {
81+ return !! this .store [node .__nodeIdentifier__ ];
82+ }
83+ }
84+ ```
85+
86+ ###### References
87+ - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
88+
89+ <br />
90+
91+
92+
4693[[ ↑] Back to top] ( #home )
You can’t perform that action at this time.
0 commit comments