<?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: Jessica Iwu</title>
    <description>The latest articles on DEV Community by Jessica Iwu (@jessicaiwu).</description>
    <link>https://dev.to/jessicaiwu</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%2F30152%2F6cdf1b43-474c-41a8-9820-5efbcbc75bfe.JPG</url>
      <title>DEV Community: Jessica Iwu</title>
      <link>https://dev.to/jessicaiwu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jessicaiwu"/>
    <language>en</language>
    <item>
      <title>Understanding Array Higher-Order Functions </title>
      <dc:creator>Jessica Iwu</dc:creator>
      <pubDate>Thu, 31 Oct 2019 10:11:05 +0000</pubDate>
      <link>https://dev.to/jessicaiwu/understanding-javascript-iterators-39pe</link>
      <guid>https://dev.to/jessicaiwu/understanding-javascript-iterators-39pe</guid>
      <description>&lt;p&gt;Having an understanding of how Array Higher-Order functions work can make complex looping operations in JavaScript very seamless.&lt;/p&gt;

&lt;p&gt;The higher-order functions to be discussed in this article are : &lt;code&gt;forEach()&lt;/code&gt;, &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At the end of this article, you'll understand what each function represents, and how to apply them in problem-solving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array.forEach()
&lt;/h2&gt;

&lt;p&gt;Running the &lt;code&gt;.forEach()&lt;/code&gt; method on an array executes a callback function for each element that exists in that array.&lt;/p&gt;

&lt;p&gt;The callback function is the block that specifies what operation is to be carried out.&lt;/p&gt;

&lt;p&gt;In the snippet below, the &lt;code&gt;.forEach()&lt;/code&gt; method iterates over every &lt;code&gt;friend&lt;/code&gt; element in the &lt;code&gt;friends&lt;/code&gt;  array, and logs each string to the console dynamically using the &lt;code&gt;${friend}&lt;/code&gt; template literal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Chief&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Somto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Elma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;friend&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`I love working with &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;friend&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// I love working with Chief&lt;/span&gt;
    &lt;span class="c1"&gt;// I love working with Somto&lt;/span&gt;
    &lt;span class="c1"&gt;// I love working with Elma&lt;/span&gt;
    &lt;span class="c1"&gt;// I love working with Zee&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Array.map()
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;.map()&lt;/code&gt; method is similar to the &lt;code&gt;.forEach()&lt;/code&gt; method except that it produces a new array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4_2E4ERa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/chr9trjjwpgftk3ygco6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4_2E4ERa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/chr9trjjwpgftk3ygco6.png" alt="Map Illustration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;.map()&lt;/code&gt; method, you can create a new array by manipulating each element in the existing array. In the illustration above, the original array contains &lt;code&gt;[2,3,4]&lt;/code&gt;, and by mapping, the new array contains the square of the original array; &lt;code&gt;[4,9,16]&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ingredients&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jam&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oat&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lemon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lettuce&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fish&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newMeal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ingredients&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ingredient&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;ingredient&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newMeal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ['J', 'o', 'l', 'l', 'o', 'f']&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newMeal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//Jollof&lt;/span&gt;

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



&lt;p&gt;In the snippet above, there’s an &lt;code&gt;ingredients&lt;/code&gt; array that is mapped to create a  &lt;code&gt;newMeal&lt;/code&gt; array by returning the first character of each ingredient. Notice that by attaching &lt;code&gt;.join(' ')&lt;/code&gt; to the &lt;code&gt;newMeal&lt;/code&gt; array, the array strings become one single string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array.filter()
&lt;/h2&gt;

&lt;p&gt;The .filter() method shares similar characteristics with the .map() method because it returns a new array. However, just like the name implies, it filters the elements in the array based on any conditions provided.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;filtering strings&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;desk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chair&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sofa&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newStack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newStack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//['desk', 'chair', 'sofa']&lt;/span&gt;

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



&lt;p&gt;&lt;em&gt;filtering numbers&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;desk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chair&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sofa&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newStack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newStack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//[17, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Array.reduce()
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;.reduce()&lt;/code&gt; method iterates an array and returns a single value. This value could be any data structure - number, string, array, etc. &lt;/p&gt;

&lt;p&gt;The callback function passed to the &lt;code&gt;reduce&lt;/code&gt; method accepts &lt;code&gt;accumulator&lt;/code&gt; and &lt;code&gt;currentValue&lt;/code&gt; as parameters and returns a single value.&lt;/p&gt;

&lt;p&gt;Using the reduce method in the code snippet below, we are able to loop through the objects in the &lt;code&gt;socialMedia&lt;/code&gt;  array in order to get the values of the &lt;code&gt;name&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; When using the reduce method on an object array, a second parameter (like the empty array in the snippet) should be added.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;socialMedia&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Instagram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jessontel.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twitter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;abc.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mediaName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;socialMedia&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mediaName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//[ 'Instagram', 'twitter' ]&lt;/span&gt;


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



&lt;p&gt;&lt;em&gt;Another quick &lt;code&gt;reduce&lt;/code&gt; example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expenseList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expenseSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;expenseList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expenseSum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2,299&lt;/span&gt;

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



&lt;p&gt;In the reduce method example above, the &lt;code&gt;expenseList&lt;/code&gt; array is reduced to the &lt;code&gt;expenseSum&lt;/code&gt; value 2,999.&lt;/p&gt;

&lt;p&gt;The first element in the array is the default accumulator value, and the second element is the current value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Iterators are very useful methods, not just in JavaScript but in programming generally. Each of them solves specific problems and make array manipulations an easy feat.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 👋🏽&lt;/p&gt;

&lt;p&gt;If you found this article useful, please let me know and share it too so that others could benefit.&lt;br&gt;
To connect with me, kindly follow me on &lt;a href="https://twitter.com/jessicaiwu_"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>es6</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Getting started with Git? 10 commands that would save you…</title>
      <dc:creator>Jessica Iwu</dc:creator>
      <pubDate>Wed, 22 Nov 2017 16:25:38 +0000</pubDate>
      <link>https://dev.to/jessicaiwu/getting-started-with-git-10-commands-that-would-save-you-cn0</link>
      <guid>https://dev.to/jessicaiwu/getting-started-with-git-10-commands-that-would-save-you-cn0</guid>
      <description>&lt;p&gt;Pushing, Pulling, fixing Merge issues among many others, used to be insurmountable problems for me because I was not familiar with git. I was always scared that I would ruin something along the way, and cause my code to break or just disappear completely. It took a while getting to understand how these processes work. After getting a grasp of some of it, I thought I should share the knowledge.  &lt;/p&gt;

&lt;p&gt;If you do not already know why Git is important, know this: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.&lt;br&gt;
~ &lt;a href="https://git-scm.com"&gt;https://git-scm.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’d talk about 10 Git commands that would help you work effectively.&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;1. git init&lt;/b&gt;&lt;/h4&gt;
 

&lt;p&gt;This is basically the starting point for you. You would need to choose a location on your system which would be used as your local Git repository. The 'init' command would create a new git repository for you. If you already have an existing project, 'init' would create a git repository in your working directory. On your terminal, cd into the directory path where your project is, and type git init.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ cd var/www/devProj
  $ git init

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;2. git clone&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;If you are working in a team, and you need to work on an already existing repository, you might need to clone it so as to have a version on your local. Git clone simply replicates the content of an existing repository, and reproduces it in a new directory. On your terminal, cd into the the directory path where you would want the project to be, and clone it there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ cd var/www/
  $ git clone path/to/the/repo

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;3. git add &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;If you have been working on a branch, you would need to add the files you have been working on to your index before you can stage for a commit. You can add a specific file using &lt;code&gt;git add&lt;/code&gt; or you can add all your new and modified files at once using &lt;code&gt;git add .&lt;/code&gt; You can git add several times before committing, as long as new changes are being made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ git add /name/of/file
    $ git add . //new and modified files

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;4. git commit &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;After you have added all the changes, you can stage all of them for a commit. This updates the Head but not the remote repository. Every time you use &lt;code&gt;git commit&lt;/code&gt;,what you are doing is to collate all the file changes you have earlier recorded using &lt;code&gt;git add .&lt;/code&gt;,and making it into an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ git commit -m "write-a-commit-message"

      //You can actually add and commit at once using -

    $ git commit -am "write-a-commit-message"

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;5. git branch &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;Git branch shows a list of all the branches available in a repository. It also shows what branch you are presently on. A branch is a portion of a project that is independent of all others.Your first commit is usually made to Git’s default branch,&lt;code&gt;master&lt;/code&gt;. If there is a need to create a new branch, you can use git branch new-branch. This new branch would be independent of all other existing branches until it is merged into another branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      $ git branch branch-name
      $ git branch -D branch-name //This deletes the created branch

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;6. git checkout &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;Git checkout is necessary when you want to leave a branch. Recall that git branch only creates a new branch, however, git checkout moves you to an already existing branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      $ git checkout branch-name //This switches you to another branch
      $ git checkout -b new-branch-name //This creates a branch and checks out to 
         it also.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;7. git status &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;This command tells you what branch you are currently on. It identifies all the changes that have been made, and all the changes that have not yet been added and committed to that branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      $ git status

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;8. git log &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;It lists all the previous commits made on that branch, the author, the time and the date of commit. This helps you keep track your activities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      $ git log

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;9. git push &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;If there are several people working on a project,the several others would definitely need to work with the new changes you have just made on a branch. For them to access your changes, you would need to push your commits to the remote repository.This way, the remote version would be updated, and can be easily accessed by others.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       $ git push origin master 

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

&lt;/div&gt;



&lt;h4&gt;&lt;b&gt;10. git pull &lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;As a developer, you might need to pull from a couple of repositories.Pulling takes files from a remote source and merges them to your local files. That way, you would have access to the same file contents as the remote repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       $ git pull origin master

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

&lt;/div&gt;



&lt;p&gt;There are a lot of other git commands, and usually, you would find them out when you exactly need them. Nevertheless, the above listed git commands would definitely be of help to you especially if you are just getting acquainted with git.&lt;/p&gt;

&lt;p&gt;No one knows it all, so, if there are other commands you would like to share, please don’t hesitate to drop them as comments.&lt;br&gt;
If you like the article, please like and share.&lt;/p&gt;

</description>
      <category>git</category>
      <category>gitcommands</category>
    </item>
  </channel>
</rss>
