<?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: Ahmed Ali Tanany</title>
    <description>The latest articles on DEV Community by Ahmed Ali Tanany (@ahmdgeek).</description>
    <link>https://dev.to/ahmdgeek</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%2F405973%2F8b985d8e-1f92-423a-a682-059fa24437a4.png</url>
      <title>DEV Community: Ahmed Ali Tanany</title>
      <link>https://dev.to/ahmdgeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmdgeek"/>
    <language>en</language>
    <item>
      <title>twoSum function JS</title>
      <dc:creator>Ahmed Ali Tanany</dc:creator>
      <pubDate>Fri, 16 Oct 2020 08:07:45 +0000</pubDate>
      <link>https://dev.to/ahmdgeek/twosum-function-js-1dlk</link>
      <guid>https://dev.to/ahmdgeek/twosum-function-js-1dlk</guid>
      <description>&lt;p&gt;returns an array of position pairs where the elements sum to the target parameter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Array Method to return array of indecies that their values sum is the target.
Array.prototype.twoSum = function (target) {
    // store this value in a normal variable to be captured 
    // by closure
    let self = this;
    // array to store the indices pair.
    let result_two_pairs = [];
    // iterate over each element and sum it with all the next 
    // elements to add the eight indices pair in the result 
    // array
    self.forEach((element) =&amp;gt; {
        let start_index = self.indexOf(element);
        this.slice(start_index,).forEach((sec_ele) =&amp;gt; {
            if ((element + sec_ele) === target) {
                if (!(result_two_pairs.includes(`(${self.indexOf(element)}, ${self.indexOf(sec_ele)})`))) {
                    result_two_pairs.push(`(${self.indexOf(element)}, ${self.indexOf(sec_ele)})`);
                };
            };
        });
    });
    // return an array containing the indices pair
    return result_two_pairs;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
