<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: prkkhan786</title>
    <description>The latest articles on DEV Community by prkkhan786 (@prkkhan786).</description>
    <link>https://dev.to/prkkhan786</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F374128%2F0d9c8acd-33c5-4894-90b0-01820b80876d.jpeg</url>
      <title>DEV Community: prkkhan786</title>
      <link>https://dev.to/prkkhan786</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prkkhan786"/>
    <language>en</language>
    <item>
      <title>How JavaScript Event Delegation Works</title>
      <dc:creator>prkkhan786</dc:creator>
      <pubDate>Sun, 13 Sep 2020 14:54:11 +0000</pubDate>
      <link>https://dev.to/prkkhan786/how-javascript-event-delegation-works-50j7</link>
      <guid>https://dev.to/prkkhan786/how-javascript-event-delegation-works-50j7</guid>
      <description>&lt;p&gt;Event delegation allows you to avoid adding event listeners to specific nodes;  instead, the event listener is added to one parent.&lt;/p&gt;

&lt;p&gt;For Example - Let's say that we have a parent UL element with several child elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul id="parent-list"&amp;gt;
    &amp;lt;li id="post-1"&amp;gt;Item 1&amp;lt;/li&amp;gt;
    &amp;lt;li id="post-2"&amp;gt;Item 2&amp;lt;/li&amp;gt;
    &amp;lt;li id="post-3"&amp;gt;Item 3&amp;lt;/li&amp;gt;
    &amp;lt;li id="post-4"&amp;gt;Item 4&amp;lt;/li&amp;gt;
    &amp;lt;li id="post-5"&amp;gt;Item 5&amp;lt;/li&amp;gt;
    &amp;lt;li id="post-6"&amp;gt;Item 6&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now something needs to be done when li element is clicked one way is to attach event listener to all the li elements but what if LI elements are frequently added and removed from the list?  Adding and removing event listeners would be a nightmare, especially if addition and removal code is in different places within your app. &lt;/p&gt;

&lt;p&gt;The better solution is to add an event listener to the parent UL element.  But if you add the event listener to the parent, how will you know which element was clicked?&lt;/p&gt;

&lt;p&gt;Simple:  when the event bubbles up to the UL element, you check the event object's target property to gain a reference to the actual clicked node.&lt;/p&gt;

&lt;p&gt;Javascript snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Get the element, add a click listener...
document.getElementById("parent-list").addEventListener("click", function(e) {
    // e.target is the clicked element!
    // If it was a list item
    if(e.target &amp;amp;&amp;amp; e.target.nodeName == "LI") {
        // List item found!  Output the ID!
        console.log("List item ", e.target.id.replace("post-", ""), " was clicked!");
    }
});

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hopefully this helps you visually the concept behind event delegation and convinces you of delegation's power!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Maximum Sum Circular Subarray</title>
      <dc:creator>prkkhan786</dc:creator>
      <pubDate>Sun, 13 Sep 2020 06:03:06 +0000</pubDate>
      <link>https://dev.to/prkkhan786/maximum-sum-circular-subarray-1c8i</link>
      <guid>https://dev.to/prkkhan786/maximum-sum-circular-subarray-1c8i</guid>
      <description>&lt;p&gt;We have to consider two cases while solving this problem:&lt;/p&gt;

&lt;p&gt;Case 1: When the maximum sum SubArray is present in the normal order of array.&lt;br&gt;
Example,&lt;br&gt;
{-10, 2, -1, 5}&lt;br&gt;
Max sum is 5&lt;/p&gt;

&lt;p&gt;{-2, 4, -1, 4, -1}&lt;br&gt;
Max sum is 7 (4+(-1)+4)&lt;br&gt;
Use Kadane’s algorithm&lt;/p&gt;

&lt;p&gt;Case 2:When max sum subArray is Present in circular fashion.&lt;br&gt;
Inversion of the array is required only to find the maximum sum in circular fashion.&lt;/p&gt;

&lt;p&gt;Example,&lt;br&gt;
{10, -12, 11}&lt;br&gt;
The max sum is 21 (11+10)&lt;br&gt;
Inverted array, {-10,12,-11}&lt;br&gt;
Maximum sum is 12&lt;br&gt;
Cumulative sum of original array is 9&lt;br&gt;
Max sum=9+12=21&lt;/p&gt;

&lt;p&gt;{12, -5, 4, -8, 11}.&lt;br&gt;
The max sum is 23 (11+12)&lt;br&gt;
Inverted array, {-12,5,-4,8,-11}&lt;br&gt;
Maximum sum is 9 (5+(-4)+8)&lt;br&gt;
Cumulative sum of original array is 14&lt;br&gt;
Max sum=14+9=23&lt;/p&gt;

&lt;p&gt;Note:&lt;br&gt;
Our array is like a ring and we have to eliminate the maximum continuous negative (i.e. the minimum sum) that implies maximum continuous positive Sum(i.e. maximum sum) in the inverted arrays.&lt;/p&gt;

&lt;p&gt;Inversion is done to apply Kadane’s algorithm which finds the maximum sum.&lt;/p&gt;

&lt;p&gt;Hence, the maximum sum of inverted array would be the minimum sum of the original array.&lt;/p&gt;

&lt;p&gt;Then, we will subtract the maximum Sum of inverted array from the Sum all the elements of the original array(i.e. cumulative sum).&lt;/p&gt;

&lt;p&gt;At last compare the max sum obtain from both the cases and print the larger one.&lt;/p&gt;

&lt;p&gt;Kadane’s Algorithm:&lt;br&gt;
Initialize:&lt;br&gt;
max_so_far = 0&lt;br&gt;
max_ending_here = 0&lt;/p&gt;

&lt;p&gt;Loop for each element of the array&lt;br&gt;
(a) max_ending_here = max_ending_here + a&lt;a href="https://dev.tob"&gt;i&lt;/a&gt; if(max_ending_here &amp;lt; 0)&lt;br&gt;
max_ending_here = 0&lt;br&gt;
© if(max_so_far &amp;lt; max_ending_here)&lt;br&gt;
max_so_far = max_ending_here&lt;br&gt;
return max_so_far&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
