<?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: Ender İMEN</title>
    <description>The latest articles on DEV Community by Ender İMEN (@enderimen).</description>
    <link>https://dev.to/enderimen</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%2F51621%2F672f82b2-5202-4ea3-b8de-6dbb402b90d7.jpeg</url>
      <title>DEV Community: Ender İMEN</title>
      <link>https://dev.to/enderimen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/enderimen"/>
    <language>en</language>
    <item>
      <title>Badge Card</title>
      <dc:creator>Ender İMEN</dc:creator>
      <pubDate>Mon, 09 Mar 2020 07:24:17 +0000</pubDate>
      <link>https://dev.to/enderimen/badge-card-21ge</link>
      <guid>https://dev.to/enderimen/badge-card-21ge</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/enderimen/embed/WNvXpaG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
    </item>
    <item>
      <title>.flat() &amp; .flatMap()</title>
      <dc:creator>Ender İMEN</dc:creator>
      <pubDate>Mon, 02 Dec 2019 05:51:29 +0000</pubDate>
      <link>https://dev.to/enderimen/flat-flatmap-ol5</link>
      <guid>https://dev.to/enderimen/flat-flatmap-ol5</guid>
      <description>&lt;p&gt;I'm currently doing research on topics of interest to Javascript. When examining the features of &lt;a href="https://thecodebarbarian.com/whats-new-in-es2019-flat-flatmap-catch"&gt;&lt;strong&gt;ECMAScript 2019 (ES2019) / ES10&lt;/strong&gt;&lt;/a&gt;, I came across the subject and liked it. I wanted to share it with you with the philosophy of sharing knowledge. 🤗&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Array.flat ()
&lt;/h2&gt;

&lt;p&gt;This method allows us to make our nested Array uniform and create a new Array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Namely;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/enderimen/embed/JjjgyeX?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In this way, the depth (1, 2, 3,…) according to the value of the intertwined series, we can bring to the first level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The lines of code on lines &lt;strong&gt;3.&lt;/strong&gt; and &lt;strong&gt;4.&lt;/strong&gt; actually do the same. Here, the parameter I liked was &lt;strong&gt;Infinity&lt;/strong&gt;. Thanks to this feature, we can use our intertwined arrays, which have a complex structure, without giving depth parameters separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; With the &lt;em&gt;flat()&lt;/em&gt; feature, we can also clear the empty fields in our corresponding array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;For example;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [8,, 3, 19];

numbers.flat ();
// [8, 3, 19]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In &lt;a href="http://es6-features.org/"&gt;&lt;strong&gt;ES6&lt;/strong&gt;&lt;/a&gt;, this could be done in different ways for a depth array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;For example;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const oneLevelDeep = [8, [3], [19]];
const flattenedArray = [] .concat (... oneLevelDeep);

// or

const flattenedArray = [] .concat.apply ([], oneLevelDeep);
// Output: [8, 3, 19]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Recursive methods or &lt;a href="https://lodash.com/"&gt;&lt;strong&gt;Lodash&lt;/strong&gt;&lt;/a&gt;, &lt;br&gt;
 &lt;a href="https://underscorejs.org/"&gt;&lt;strong&gt;Underscore&lt;/strong&gt;&lt;/a&gt; libraries can do this process in a short way.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Array.flatMap()
&lt;/h2&gt;

&lt;p&gt;This is the same as using &lt;strong&gt;.map()&lt;/strong&gt; followed by &lt;strong&gt;.flat()&lt;/strong&gt; or &lt;strong&gt;.flat(1)&lt;/strong&gt;. In short, &lt;strong&gt;.flatMap()&lt;/strong&gt; &lt;strong&gt;maps each value to a new value&lt;/strong&gt;, and then the resulting array becomes &lt;strong&gt;a maximum depth.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fibonacci = [0, 1, 1, 2, 3];
fibonacci.map(f =&amp;gt; [f, f * 2])
         .flat();

// [Array(2), Array(2), Array(2), …]
// 0: (2)[0, 0] 
// 1: (2)[1, 2]
// 2: (2)[1, 2]
// 3: (2)[2, 4]
// 4: (2)[3, 6]

// Output: [0, 0, 1, 2, 1, 2, 2, 4, 3, 6]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we use &lt;em&gt;.flatMap()&lt;/em&gt;; &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/enderimen/embed/OJJKxde?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In short, considering the complex &lt;em&gt;JSON&lt;/em&gt; result from the &lt;em&gt;API&lt;/em&gt;, I can say that this is a very useful development.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wish = ['stay', ['healthy', ['🖖']]];
console.log(wish.flat(Infinity));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>flat</category>
      <category>flatmap</category>
      <category>es9</category>
      <category>es6</category>
    </item>
  </channel>
</rss>
