<?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: Cherag Verma</title>
    <description>The latest articles on DEV Community by Cherag Verma (@cheragv).</description>
    <link>https://dev.to/cheragv</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%2F325479%2F8f5f9b5e-7c68-4468-9620-3173370ca334.jpeg</url>
      <title>DEV Community: Cherag Verma</title>
      <link>https://dev.to/cheragv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cheragv"/>
    <language>en</language>
    <item>
      <title>Polyfill for Array.reduce() Javascript</title>
      <dc:creator>Cherag Verma</dc:creator>
      <pubDate>Mon, 04 May 2020 19:45:48 +0000</pubDate>
      <link>https://dev.to/cheragv/polyfill-for-array-reduce-javascript-55fb</link>
      <guid>https://dev.to/cheragv/polyfill-for-array-reduce-javascript-55fb</guid>
      <description>&lt;p&gt;Just wrote a code for polyfill reduce() in JavaScript, thought I will share it will you all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array.prototype.myReduce = function(fn, initial) {
    let values = this;

    values.forEach(item =&amp;gt; {
        initial = initial !== undefined ? fn(initial, item) : item
    })

    return initial;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Using the above
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var values = [2, 5, 5]
values.reduce((a, b) =&amp;gt; a * b)  // 50
values.myReduce((a, b) =&amp;gt; a * b)  // 50

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



&lt;p&gt;I have dry tested it for multiple outputs. Do let me know if there can be any improvements. &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>reduce</category>
      <category>polyfill</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
