File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 11115 . [ Write a function to find the corresponding node in two identical DOM trees] ( #Q5 )
12126 . [ Write a function to get depth of a given DOM tree] ( #Q6 )
13137 . [ Implement a function to get the root node of a given DOM fragment] ( #Q7 )
14+ 8 . [ Implement a function to get unique tag names in a given DOM tree] ( #Q8 )
1415
1516---
1617
@@ -227,6 +228,36 @@ function getRootNode (tree) {
227228###### References
228229- https://javascript.info/dom-navigation
229230
231+
232+ #### Q8
233+ ### Implement a function to get unique tag names in a given DOM tree
234+
235+ ``` js
236+ /**
237+ * @param {HTMLElement | null} tree
238+ * @return {Array}
239+ */
240+ function getUniqueTags (root , result = new Set ()) {
241+ if (! root) return [];
242+
243+ if (! result .has (root .tagName )) {
244+ result .add (root .tagName );
245+ }
246+
247+ if (root .hasChildNodes ()) {
248+ for (let child of root .children ) {
249+ getUniqueTags (child, result)
250+ }
251+ }
252+
253+ return [... result];
254+ }
255+ ```
256+
257+ ###### References
258+ - https://bigfrontend.dev/problem/get-DOM-tags
259+
260+
230261<br />
231262
232263[[ ↑] Back to top] ( #home )
You can’t perform that action at this time.
0 commit comments