{"id":97927,"date":"2025-02-17T21:36:41","date_gmt":"2025-02-17T18:06:41","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/dom-challenge-%d8%b4%d9%85%d8%a7%d8%b1%d9%87-1\/"},"modified":"2025-02-17T21:36:41","modified_gmt":"2025-02-17T18:06:41","slug":"dom-challenge-%d8%b4%d9%85%d8%a7%d8%b1%d9%87-1","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/dom-challenge-%d8%b4%d9%85%d8%a7%d8%b1%d9%87-1\/","title":{"rendered":"DOM Challenge &#8211; \u0634\u0645\u0627\u0631\u0647 1"},"content":{"rendered":"<p>\u0645\u0646 \u0642\u0635\u062f \u062f\u0627\u0631\u0645 \u062d\u062f\u0648\u062f 30 \u067e\u0633\u062a \u0631\u0627 \u0628\u0646\u0648\u06cc\u0633\u0645 \u06a9\u0647 \u0634\u0627\u0645\u0644 \u0633\u0624\u0627\u0644\u0627\u062a \u0645\u062e\u062a\u0644\u0641 \u0645\u0631\u0628\u0648\u0637 \u0628\u0647 Traversal \u060c \u062f\u0633\u062a\u06a9\u0627\u0631\u06cc \u0648 \u0628\u0647\u06cc\u0646\u0647 \u0633\u0627\u0632\u06cc DOM \u0627\u0633\u062a.<\/p>\n<p>\u0633\u0648\u0627\u0644 \u0627\u0645\u0631\u0648\u0632 \u0645\u0631\u0628\u0648\u0637 \u0628\u0647 Dom Traversal \u0627\u0633\u062a<\/p>\n<p>\u0633\u0648\u0627\u0644:<br \/>\n<strong>\u0627\u062c\u062f\u0627\u062f \u0645\u0634\u062a\u0631\u06a9 \u062f\u0648 \u0639\u0646\u0635\u0631 DOM \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0631\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0646\u06cc\u062f.<\/strong><\/p>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u0633\u0624\u0627\u0644 \u0645\u0627 \u062f\u0631\u062e\u062a DOM \u062f\u0627\u0631\u06cc\u0645 \u0648 \u0628\u0627\u06cc\u062f \u0627\u062c\u062f\u0627\u062f \u0645\u0634\u062a\u0631\u06a9 \u06af\u0631\u0647 \u0647\u0627\u06cc \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0631\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0646\u06cc\u0645. \u0627\u0648\u0644\u06cc\u0646 \u0631\u0648\u06cc\u06a9\u0631\u062f\u06cc \u06a9\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u0645 \u0628\u0647 \u0622\u0646 \u0641\u06a9\u0631 \u06a9\u0646\u0645 \u062c\u0645\u0639 \u0622\u0648\u0631\u06cc \u062a\u0645\u0627\u0645 \u06af\u0631\u0647 \u0647\u0627\u06cc \u0648\u0627\u0644\u062f\u06cc\u0646 \u0647\u0631 \u062f\u0648 \u0639\u0646\u0635\u0631 \u0648 \u06cc\u0627\u0641\u062a\u0646 \u0627\u0648\u0644\u06cc\u0646 \u06af\u0631\u0647 \u0645\u0634\u062a\u0631\u06a9 \u0627\u0633\u062a.<\/p>\n<p>\u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06cc\u0646 \u0631\u0648\u0634 \u060c \u0648\u0627\u0644\u062f\u06cc\u0646 \u0631\u0627 \u0628\u062f\u0633\u062a \u0622\u0648\u0631\u06cc\u0645\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const parentList = (element)=&gt;{\n    let el = element;\n   const list = [];\n    while(true){\n        list.push(el);\n\n        if(!el.parentNode) break;\n        el = el.parentNode;\n    }\n\n    return list;\n}\n<\/code><\/pre>\n<\/div>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0627\u0632 \u0627\u06cc\u0646 \u0644\u06cc\u0633\u062a \u0628\u0631\u0627\u06cc \u06cc\u0627\u0641\u062a\u0646 LCA \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u0645 &#8211;\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>\nconst findLCA = (el1, el2)=&gt;{\n    const parentList1 = parentList(el1);\n    const parentList2 = parentList(el2);\n\n    for(let i=0; i&lt;parentList1.length; i++){\n     if(parentList2.includes(parentList1[i])){\n         return parentList1[i];\n     } \n    }\n    return null;\n}\n\n<\/code><\/pre>\n<\/div>\n<p>\u0627\u06cc\u0646 \u0631\u0627\u0647 \u062d\u0644 \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u062f \u060c \u0627\u0645\u0627 \u0628\u0647 \u062f\u0644\u06cc\u0644 \u0628\u0631\u0631\u0633\u06cc () \u062f\u0631 \u062f\u0627\u062e\u0644 \u062d\u0644\u0642\u0647 \u060c \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc O (n\u00b2) \u062f\u0627\u0631\u062f.<\/p>\n<p>\u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0627\u06cc\u0646 \u06a9\u0627\u0631 \u0631\u0627 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 Set \u0628\u0631\u0627\u06cc \u0630\u062e\u06cc\u0631\u0647 \u0644\u06cc\u0633\u062a \u0648\u0627\u0644\u062f\u06cc\u0646 \u0628\u0647\u0628\u0648\u062f \u0628\u062e\u0634\u06cc\u0645 \u060c \u062a\u0627 \u0628\u062a\u0648\u0627\u0646\u06cc\u0645 \u0627\u0632 \u0622\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u0645 <code>parentList2.has(parentList1[i])<\/code>\u060c \u0627\u06cc\u0646 \u0627\u0632 O (1) \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0627\u0633\u062a \u060c \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646 \u0628\u0631\u0627\u06cc \u06a9\u062f \u0645\u0627 o (n) \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f.<\/p>\n<p>\ud83d\udca1 \u062a\u0648\u062c\u0647: \u0627\u06cc\u0646 \u067e\u0633\u062a \u0647\u0627 \u062f\u0631 \u062f\u0631\u062c\u0647 \u0627\u0648\u0644 \u0628\u0631\u0627\u06cc \u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0648 \u062a\u0645\u0631\u06cc\u0646 \u0645\u0646 \u0627\u0633\u062a. \u0645\u0646\u0638\u0648\u0631 \u0622\u0646\u0647\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0631\u0627\u0647\u0646\u0645\u0627\u06cc \u0631\u0633\u0645\u06cc \u0646\u06cc\u0633\u062a \u0627\u0645\u0627 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0628\u0631\u0627\u06cc \u06a9\u0633\u06cc \u06a9\u0647 \u0628\u0631\u0627\u06cc \u0645\u0635\u0627\u062d\u0628\u0647 \u0622\u0645\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f \u0645\u0641\u06cc\u062f \u0628\u0627\u0634\u062f.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0645\u0646 \u0642\u0635\u062f \u062f\u0627\u0631\u0645 \u062d\u062f\u0648\u062f 30 \u067e\u0633\u062a \u0631\u0627 \u0628\u0646\u0648\u06cc\u0633\u0645 \u06a9\u0647 \u0634\u0627\u0645\u0644 \u0633\u0624\u0627\u0644\u0627\u062a \u0645\u062e\u062a\u0644\u0641 \u0645\u0631\u0628\u0648\u0637 \u0628\u0647 Traversal \u060c \u062f\u0633\u062a\u06a9\u0627\u0631\u06cc \u0648 \u0628\u0647\u06cc\u0646\u0647 \u0633\u0627\u0632\u06cc DOM \u0627\u0633\u062a. \u0633\u0648\u0627\u0644 \u0627\u0645\u0631\u0648\u0632 \u0645\u0631\u0628\u0648\u0637 \u0628\u0647 Dom Traversal \u0627\u0633\u062a \u0633\u0648\u0627\u0644: \u0627\u062c\u062f\u0627\u062f \u0645\u0634\u062a\u0631\u06a9 \u062f\u0648 \u0639\u0646\u0635\u0631 DOM \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0631\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0646\u06cc\u062f. \u062f\u0631 \u0627\u06cc\u0646 \u0633\u0624\u0627\u0644 \u0645\u0627 \u062f\u0631\u062e\u062a DOM \u062f\u0627\u0631\u06cc\u0645 \u0648 \u0628\u0627\u06cc\u062f \u0627\u062c\u062f\u0627\u062f \u0645\u0634\u062a\u0631\u06a9 \u06af\u0631\u0647 \u0647\u0627\u06cc \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 &hellip;<\/p>\n","protected":false},"author":2,"featured_media":97928,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/media2.dev.to\/dynamic\/image\/width=1000,height=500,fit=cover,gravity=auto,format=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5usntxozp6n2sn3v7byh.png","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-97927","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/97927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=97927"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/97927\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/97928"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=97927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=97927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=97927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}