<?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: Hasib Muhammad</title>
    <description>The latest articles on DEV Community by Hasib Muhammad (@hasib).</description>
    <link>https://dev.to/hasib</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%2F69849%2Fad54e0c7-c15d-4917-ba67-93059ec0ea8d.png</url>
      <title>DEV Community: Hasib Muhammad</title>
      <link>https://dev.to/hasib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hasib"/>
    <language>en</language>
    <item>
      <title>A basic use case of Arguments or Rest Parameters</title>
      <dc:creator>Hasib Muhammad</dc:creator>
      <pubDate>Mon, 19 Jul 2021 08:18:05 +0000</pubDate>
      <link>https://dev.to/hasib/a-basic-use-case-of-arguments-or-rest-parameters-400l</link>
      <guid>https://dev.to/hasib/a-basic-use-case-of-arguments-or-rest-parameters-400l</guid>
      <description>&lt;h1&gt;
  
  
  Seek and Destroy
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;destroyer([1, 2, 3, 1, 2, 3], 2, 3) should return [1, 1].&lt;/code&gt;&lt;br&gt;
&lt;code&gt;destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) should return [1, 5, 1].&lt;/code&gt;&lt;br&gt;
&lt;code&gt;destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1].&lt;/code&gt;&lt;br&gt;
&lt;code&gt;destroyer([2, 3, 2, 3], 2, 3) should return [].&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make an array with with the parameters except the 1st array&lt;/li&gt;
&lt;li&gt;Filter the 1st array excluding the new array items&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Using Arguments:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function destroyer(arr) {
    let newAr = [];
    for( let i = 1; i &amp;lt; arguments.length; i++ ) {
      newAr.push( arguments[i] );
    }
    return arr.filter( item =&amp;gt; !newAr.includes(item) );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Rest Parameters:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const destroyer = (...arr) =&amp;gt; {
    const checkedArr = [...arr][0];

    let newAr = [];
    for( let i = 1; i &amp;lt; [...arr].length; i++ ) {
      newAr.push( [...arr][i] );
    }

    return checkedArr.filter( item =&amp;gt; !newAr.includes(item) );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>arguments</category>
      <category>restparameters</category>
      <category>es6</category>
    </item>
  </channel>
</rss>
