<?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: Manu Magalhães</title>
    <description>The latest articles on DEV Community by Manu Magalhães (@manumagalhaes).</description>
    <link>https://dev.to/manumagalhaes</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%2F448253%2F42593c0a-31d9-4bdc-9b37-b5b19b9536d9.jpeg</url>
      <title>DEV Community: Manu Magalhães</title>
      <link>https://dev.to/manumagalhaes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manumagalhaes"/>
    <language>en</language>
    <item>
      <title>What is your greatest issue with git/GitHub?</title>
      <dc:creator>Manu Magalhães</dc:creator>
      <pubDate>Thu, 06 Aug 2020 21:31:13 +0000</pubDate>
      <link>https://dev.to/manumagalhaes/what-is-your-greatest-issue-with-git-github-3b69</link>
      <guid>https://dev.to/manumagalhaes/what-is-your-greatest-issue-with-git-github-3b69</guid>
      <description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;I'm preparing a presentation on #git #github and would like your input.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is your greatest issue with git/GitHub?&lt;/li&gt;
&lt;li&gt;What would you like to understand better?&lt;/li&gt;
&lt;li&gt;What is that thing you always have to google?&lt;/li&gt;
&lt;li&gt;What is your best tip?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Comparing JS iteration methods (map, filter, forEach, reduce + loops)</title>
      <dc:creator>Manu Magalhães</dc:creator>
      <pubDate>Sat, 20 Apr 2019 10:56:00 +0000</pubDate>
      <link>https://dev.to/manumagalhaes/comparing-js-iteration-methods-map-filter-foreach-reduce-loops-le</link>
      <guid>https://dev.to/manumagalhaes/comparing-js-iteration-methods-map-filter-foreach-reduce-loops-le</guid>
      <description>&lt;p&gt;&lt;em&gt;Part III of “&lt;/em&gt; &lt;em&gt;Weird questions from my first month of coding”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are several ways to iterate through arrays in JavaScript. They all have one thing in common: they execute a given function in &lt;em&gt;each item&lt;/em&gt; of your array; the difference is what you get in return.&lt;/p&gt;

&lt;p&gt;Here I assume you know &lt;em&gt;how&lt;/em&gt; to use each iterator. It’s ok if you get confused by them or if you’re note sure of &lt;em&gt;when&lt;/em&gt; to use them, though. It took me a few weeks to understand the proper use of different iterators, and I hope this post will help you clear this out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2RKG_9S3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/527/1%2AAgYSfRbK6jtTqiZosUp19g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2RKG_9S3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/527/1%2AAgYSfRbK6jtTqiZosUp19g.png" alt="" width="527" height="370"&gt;&lt;/a&gt;The table I wish I had when I learned JavaScript iteration methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  .map = transform
&lt;/h3&gt;

&lt;p&gt;Use map when you want to &lt;strong&gt;transform&lt;/strong&gt; an array without changing its original values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5_K8YWkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/264/1%2AWOKdroo-6B0G6s0QJNssAQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5_K8YWkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/264/1%2AWOKdroo-6B0G6s0QJNssAQ.png" alt="" width="264" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IRL&lt;/strong&gt; (In real life): You can use this method to iterate through API data to show each entry in your website — instead of hard coding them in each div, for example.&lt;/p&gt;

&lt;h3&gt;
  
  
  .filter = select
&lt;/h3&gt;

&lt;p&gt;Use filter when you want to &lt;strong&gt;select&lt;/strong&gt; certain elements in your array. When an element meets the conditions given in your function (in other words, it’s true), it is included in the returned array:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LknoxZJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/290/1%2Asn_XOVfg0kxyDH1xv3Gh4A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LknoxZJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/290/1%2Asn_XOVfg0kxyDH1xv3Gh4A.png" alt="" width="290" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IRL:&lt;/strong&gt; If you have a database of clients and need to find only those over 18 yo, you can use filter to do it.&lt;/p&gt;

&lt;h3&gt;
  
  
  .forEach = execute
&lt;/h3&gt;

&lt;p&gt;forEach is useful when you simply need to &lt;strong&gt;run a function&lt;/strong&gt; through each item in the array, with no need to get a return.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F8DCH1x0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/366/1%2Ar5ddWJiwKdxrHLWFbyQAxA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F8DCH1x0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/366/1%2Ar5ddWJiwKdxrHLWFbyQAxA.png" alt="" width="366" height="152"&gt;&lt;/a&gt;You can see that &lt;em&gt;oddsPlusOne&lt;/em&gt; is processing the requested function but, in the end, it’s undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IRL:&lt;/strong&gt; You can use forEach to process and save data in your database.&lt;/p&gt;

&lt;h3&gt;
  
  
  .reduce = reduce
&lt;/h3&gt;

&lt;p&gt;If you need your &lt;strong&gt;array to be reduced to a single value&lt;/strong&gt; , reduce is a very elegant solution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WHpdv0kB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/296/1%2AE4ztdJyxvRz9LYoe3ijCcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WHpdv0kB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/296/1%2AE4ztdJyxvRz9LYoe3ijCcg.png" alt="" width="296" height="82"&gt;&lt;/a&gt;In this example, the function is multiplying 1 x 3 x 5 x 7&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IRL:&lt;/strong&gt; The classic example is to get the sum of numbers in a certain array. For example, if you have a catalog of books in JSON format, you can check how many of those books were published when your grandma was your age.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mwX21Nlu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/707/1%2ArSeebWb5AllYnqdVzy2KEQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mwX21Nlu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/707/1%2ArSeebWb5AllYnqdVzy2KEQ.png" alt="" width="707" height="398"&gt;&lt;/a&gt;Would emojis explain it better?&lt;/p&gt;

&lt;h3&gt;
  
  
  for loop = until condition is false
&lt;/h3&gt;

&lt;p&gt;It’s useful to use this iteration when you know how many times you want to execute a function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V2mE0DLZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/189/1%2AMsaj45agPPDAh8nLxGQ1IQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V2mE0DLZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/189/1%2AMsaj45agPPDAh8nLxGQ1IQ.png" alt="" width="189" height="217"&gt;&lt;/a&gt;Here, we add 10 to numbers up to 9. When the condition becomes false (meaning, i=10), the function stops executing.&lt;/p&gt;

&lt;h3&gt;
  
  
  while loop = while condition is true
&lt;/h3&gt;

&lt;p&gt;If you don’t know in advance how many times to execute a function, a while loop might be a good idea. In real life, this iteration could be used to slideshow your phone pictures until you tap stop, for example. Or if your gaming character keeps running for as long as you press an arrow key. In both cases, you don’t know beforehand when the user will interrupt the loop. But be careful: if you set while condition to true, you may accidentally create an infinite loop Oo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rlDVUEtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/480/0%2AmvOVwzZ4zjH2HsWz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rlDVUEtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/480/0%2AmvOVwzZ4zjH2HsWz.jpg" alt="" width="480" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  However…
&lt;/h3&gt;

&lt;p&gt;Please note that there might not be &lt;em&gt;one&lt;/em&gt; right answer to your function. If you look closely, you’ll see that a for loop can well do the job of a map or reduce method, or that while loops work fine replacing for loops. But the more we code, the more we see that some options fit better than others. You may pick a certain method to make your code more readable, or you might decide for another one for increased performance. In any case, if you know your tools you have a larger set of options to make your code more efficient and friendly to the machines and to your fellow humans too :)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Weird questions from my first month of coding” series&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Part I: &lt;a href="https://medium.com/@manumagalhaes/how-array-indexes-values-work-in-for-loops-289163855f87?source=friends_link&amp;amp;sk=72f44ce790e8381c6ff36f69f444abda"&gt;How array indexes &amp;amp; values work in for loops&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Part II: &lt;a href="https://medium.com/@manumagalhaes/how-to-write-functions-that-go-inside-a-filter-method-ffefe1b83e9c?source=friends_link&amp;amp;sk=1c91261f94c8aeb8a7dcbc137277047b"&gt;How to write functions that go inside a filter method&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




</description>
      <category>javascript</category>
      <category>methods</category>
      <category>iteration</category>
      <category>loop</category>
    </item>
  </channel>
</rss>
