<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dilan Tharidu Sangeeth on Medium]]></title>
        <description><![CDATA[Stories by Dilan Tharidu Sangeeth on Medium]]></description>
        <link>https://medium.com/@dtsangeeth?source=rss-4761ca2543e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UhMZMvAyLC1SdCf1_8n9aQ.jpeg</url>
            <title>Stories by Dilan Tharidu Sangeeth on Medium</title>
            <link>https://medium.com/@dtsangeeth?source=rss-4761ca2543e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:58:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dtsangeeth/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JavaScript ES6- Array and Object Destructuring End To End]]></title>
            <link>https://medium.com/geekculture/javascript-es6-array-and-object-destructuring-end-to-end-b3f23cb9968f?source=rss-4761ca2543e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3f23cb9968f</guid>
            <category><![CDATA[array-destructuring]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[object-destructuring]]></category>
            <dc:creator><![CDATA[Dilan Tharidu Sangeeth]]></dc:creator>
            <pubDate>Mon, 07 Jun 2021 20:55:47 GMT</pubDate>
            <atom:updated>2021-06-12T19:56:12.825Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript ES6- Array and Object Destructuring.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*1Wb16sKH02pyIFh6GY8gMw.png" /><figcaption>ES6 new Features destructuring</figcaption></figure><h3>What is this Destructuring in JavaScript?</h3><blockquote>Take elements from Array or properties from Object and set them as local Variables. it possible to unpack values from arrays, or properties from objects, This is a very powerful way to <strong>assign the values as distinct Variables</strong> in ES6 (ES2015). We can mainly divide these destructuring into two parts.</blockquote><ol><li><strong><em>Array Destructuring.</em></strong></li><li><strong><em>Object Destructuring.</em></strong></li></ol><p>In older javascript style we extract each element from an array and object with a line.</p><pre>let array = [ 5, 6, 9, 1, 3, 4, 8];<br>const valOne = array[0];</pre><pre>console.log(valOne);<br><strong><em>// output: 5</em></strong></pre><pre>const planet = {  <br>name: &#39;Hosnian Prime&#39;,  <br>faction: &#39;New Republic&#39;,  <br>weather: &#39;Temperate&#39;<br>};</pre><pre>const plantName = planet.name;<br>console.log(plantName); <br><strong><em>// Output: &#39;Hosnian Prime&#39;</em></strong></pre><p>So, If there is 100 element of an object we to had to write 100 lines for extraction but using ES6 destructuring we can solve this in one line. With a single line, we may extract multiple elements from an object or an array.</p><pre>const organizations = [&#39;Pyke&#39;, &#39;Black Sun&#39;, &#39;Kanjiklub&#39;, &#39;Crimson&#39;];<br>const [firstGang, secondGang, ...rest] = organizations;</pre><pre>console.log(firstGang); <strong><em>// output: &quot;Pyke&quot;</em></strong></pre><p><strong>This technique can make your JS code more concise and more readable.</strong></p><h3>Array destructuring</h3><p>If you want to get an element from the specified array as a separate distinct variable. you can take advantage of <strong>destructuring</strong> to achieve your goal using a single line of code.</p><p>simply, The regular way is to access an element in the array. first, we iterate the given array and access each of the elements one by one. but when use this array destructuring we do not need to use any of the indexes or loop. that is the beauty of <strong><em>Array destructuring</em></strong><em> </em>in<strong> ES6</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8149e25ba4267ba0d2aa7354485e754/href">https://medium.com/media/b8149e25ba4267ba0d2aa7354485e754/href</a></iframe><p>without using variable names. instead, we can use <strong>object destructuring</strong> like syntax — by accessing elements with an index. as well as You can also set <strong>default values</strong> if you wish! That way, even if the passed array doesn’t have enough values, all your variables will have a defined value</p><pre>const arr = [&#39;Pyke&#39;, &#39;Black Sun&#39;, &#39;Kanjiklub&#39;, &#39;Crimson&#39;];</pre><pre>const {0: first , 3: fourth} = arr;</pre><pre>console.log(first) <strong><em>//output: &#39;Pyke&#39;</em></strong><br>console.log(fourth) <strong><em>//output: &#39;Crimson&#39;</em></strong></pre><pre>const {0: first, 3: fourth, 9: tenth = &#39;moon&#39;} = arr;<br>console.log(tenth) <strong><em>//output: &#39;moon&#39;</em></strong><br><strong><em>// here index number 10th is undifine so, default value will assign for this tenth variable.</em></strong></pre><h3>Swapping Variables</h3><p>Typically, we have to use a temporary variable for swapping.</p><pre>let a = 1;<br>let b = 2;<br>let temp;<br><br>temp = a;<br>a = b;<br>b = temp;</pre><pre>console.log(a) <strong><em>//output: 2</em></strong><br>console.log(b) <strong><em>//output: 1</em></strong></pre><p>can you believe, we can do this with a single line like the below code?</p><pre>let a = 1;<br>let b = 2;</pre><pre><strong>[a, b] = [b, a];</strong></pre><pre>console.log(a) <strong><em>//output: 2</em></strong><br>console.log(b) <strong><em>//output: 1</em></strong></pre><p>What makes destructuring even more interesting is the ability to swap <em>n</em> number of variables:</p><pre><strong>[a, b, c] = [b, c, a]</strong></pre><h3>Omitting element Using the Rest Syntax (…)</h3><p>The rest syntax is meant to pick up multiple elements and set them into a new element. When destructuring, this is handy for removing a certain value. An array can also be cloned using the expression below.</p><pre>const arr = [&quot;Hello&quot;, &quot;How&quot; , &quot;are&quot;, &quot;you&quot;];<br>const [ hello , , ...others ] = arr;</pre><pre>console.log(others)<em> </em><strong><em>//output: [&quot;are&quot;, &quot;you&quot;]</em></strong></pre><h3>Combine multiple arrays and Assign exist array into a new array.</h3><p>Usually, there are several methods to combine multiple arrays together. normally we can use <strong><em>.concat( ) method for </em></strong>merge two arrays in javascript.</p><pre>const hege = [&quot;Cecilie&quot;, &quot;Lone&quot;];<br>const stale = [&quot;Emil&quot;, &quot;Tobias&quot;, &quot;Linus&quot;];<br>const children = hege.concat(stale);</pre><pre>console.log(children); <br><strong><em>//output: [&quot;Cecilie&quot;, &quot;Lone&quot;,&quot;Emil&quot;, &quot;Tobias&quot;, &quot;Linus&quot;]</em></strong></pre><p>but using ES6 destructuring we can combine multiple arrays into one new array like the below example.</p><pre>const hege = [&quot;Cecilie&quot;, &quot;Lone&quot;];<br>const stale = [&quot;Emil&quot;, &quot;Tobias&quot;, &quot;Linus&quot;];<br>const newl = [&quot;Singh&quot;, &quot;Shakya&quot;];</pre><pre>const newArray = [...hege , ...stale , ...newl ];<br>console.log(newArray);</pre><pre><strong><em>//output: [&quot;Cecilie&quot;,&quot;Lone&quot;,&quot;Emil&quot;,&quot;Tobias&quot;,&quot;Linus&quot;,</em></strong><strong><em>&quot;Singh&quot;, &quot;Shakya&quot;]</em></strong></pre><h3>Common use cases in Array destructuring</h3><p>When we are going to write a function. There is a requirement to pass an array as a parameter but you want to only use the first and second elements in that given array. as well as you have to return both adding value and multiplication value. Then, the below use case will be a good example for this scenario.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/615749a946c3b67918544c6a100877ea/href">https://medium.com/media/615749a946c3b67918544c6a100877ea/href</a></iframe><p>Here I have demonstrated bubble sort algorithm using destructuring swap tool,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/481af538e7a161b83803de4c967441bd/href">https://medium.com/media/481af538e7a161b83803de4c967441bd/href</a></iframe><h3>Object Destructuring</h3><p>Destructuring on objects lets you bind variables to different properties of an object. The property to be bound is specified first, followed by the variable to which the value will be bound. You’ll notice that it’s a lot like what we did with arrays.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/532a06ebd78e6e09960aecc363cfdff5/href">https://medium.com/media/532a06ebd78e6e09960aecc363cfdff5/href</a></iframe><p>As you can see in the instance above, we named the variables the same way we named the object’s keys. Nonetheless, Variables having names that <strong>differ from the keys</strong> can be defined.</p><pre>const planet = {  <br>name: &#39;Hosnian Prime&#39;,  <br>faction: &#39;New Republic&#39;,  <br>weather: &#39;Temperate&#39;<br>};</pre><pre>const { <br>name: system, <br>faction: team, <br>weather: conditions } = planet;</pre><pre>console.log(system); <strong><em>// Output: &#39;Hosnian Prime&#39;</em></strong><br>console.log(team); <strong><em>// Output: &#39;New Republic&#39;</em></strong><br>console.log(conditions); <strong><em>// Output: &#39;Temperate&#39;</em></strong></pre><h4>we can also set <strong>default values like the below example</strong>.</h4><pre>const planet = {  <br>name: &#39;Hosnian Prime&#39;<br>};</pre><pre>const { <br>name: system = &#39;default planet&#39;, <br>faction: team = &#39;default faction&#39;, <br>weather: conditions = &#39;default conditions&#39;<br>} = planet;</pre><pre>console.log(system); <strong><em>// Output: &#39;Hosnian Prime&#39;</em></strong><br>console.log(team); <strong><em>// Output: &#39;</em>default faction<em>&#39;</em></strong><br>console.log(conditions); <strong><em>// Output: &#39;</em>default conditions<em>&#39;</em></strong></pre><h3>Combine multiple objects and Assign exist objects into a new object.</h3><p>This is a very special case in Object merge. in Object<strong><em> </em></strong>also key (“property”)is <strong>unique</strong> and <strong>associated with a single value. </strong>according to<strong> ES6 </strong>features when we assign a new value to an existing property. the new value will be overridden with the previous value.</p><p>This Article explains properly how to <strong>Object</strong> works in ES6.</p><p><a href="https://dtsangeeth.medium.com/count-duplicates-in-array-using-javascript-map-and-object-es6-new-features-a22bd9fd6a16">Count Duplicates in Array using JavaScript MAP and Object (ES6 new features)</a></p><p>Then if there are <strong>unique keys </strong>that each property will overwrite. The below code example explains how it works and implement in JS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a9c4f0912caa29a062aa404e174f524/href">https://medium.com/media/5a9c4f0912caa29a062aa404e174f524/href</a></iframe><h3>Common use cases in Object destructuring</h3><p>As I mentioned earlier if we have to call the function with passing object variable as parameters. Then, the below example will guide how to implement that and how to use destructuring with that use case. here I have demonstrated how to Access Nested Properties and how to Set Default Values for each property in a specified object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/483d9fa2e22dd954e4e464093a14affd/href">https://medium.com/media/483d9fa2e22dd954e4e464093a14affd/href</a></iframe><p>Thank You!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3f23cb9968f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/javascript-es6-array-and-object-destructuring-end-to-end-b3f23cb9968f">JavaScript ES6- Array and Object Destructuring End To End</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Count Duplicates in Array using JavaScript MAP and Object (ES6 new features)]]></title>
            <link>https://dtsangeeth.medium.com/count-duplicates-in-array-using-javascript-map-and-object-es6-new-features-a22bd9fd6a16?source=rss-4761ca2543e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a22bd9fd6a16</guid>
            <category><![CDATA[duplicate]]></category>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dilan Tharidu Sangeeth]]></dc:creator>
            <pubDate>Sat, 29 May 2021 23:14:31 GMT</pubDate>
            <atom:updated>2021-07-13T21:52:47.687Z</atom:updated>
            <content:encoded><![CDATA[<h3>Count Duplicates in Array using JavaScript Map() and Object() (ES6 new features)</h3><p><a href="https://github.com/sriThariduSangeeth/RAPID-T4-CL-with-Krish">Algorithms-and-Data-Structures</a></p><figure><img alt="Background image" src="https://cdn-images-1.medium.com/max/1024/1*SX8Kq3-0hAAn38CvpveopA.png" /><figcaption>Data Structures and Algorithms</figcaption></figure><h4>How to define Map and Object in JavaScript?</h4><p><strong>What is Map?</strong></p><p><strong>Map</strong> is a data structure type that helps in storing the data as <strong>key-value</strong> pairs. It has <strong>each unique key</strong> and a <strong>value mapped to it. </strong>Additionally, because each stored key is unique, There are no duplicate keys on the map. but Value can be duplicate. <strong>The map</strong> is an instance of an Object.</p><pre>var map = new Map();<br>console.log(map instanceof Object); //true</pre><p>Special case: <strong>key and value in Map can be in any data type,</strong> <em>not limited</em> to only string or integer. as an example in Java when we define HashMap we have to specify what are the data types in key and value.</p><pre>Map&lt;String,String&gt; map = new HashMap&lt;String,String&gt;()</pre><p>but in this case, we do not need to mention what are the data types when we define maps in JavaScript. I have mentioned below how to define Map object in JS as an example.</p><blockquote><strong>let variable_map = new Map();</strong></blockquote><pre>let sampleMap = new Map();</pre><pre>sampleMap.set(&quot;key1&quot;, 1);</pre><pre>sampleMap.set(&quot;key2&quot;, &quot;value1&quot;);</pre><pre>sampleMap.set(1, &quot;value2&quot;);</pre><p><strong>What is an Object?</strong></p><p>The <strong>object</strong> follows the same concept as that of a map i.e. using <strong>key-value</strong> <strong>pairs</strong> for storing data. <strong>The object</strong> is definitely <strong>not</strong> an instance of <strong>Map</strong>. <em>all objects in Javascript are </em><strong><em>instances of Object. </em></strong>In Object<strong><em> </em></strong>also key (“property”)is <strong>unique</strong> and <strong>associated with a single value. </strong>according to<strong> ES6 </strong>features when we assign a new value to an existing property. the new value will be overridden with the previous value.</p><pre>var obj = new Object();<br>console.log(obj instanceof Map); //false</pre><ul><li>In Object, the data-type of the key is restricted to integer, strings, and symbols. But in <strong>Map,</strong> it can be <strong>any data type</strong> (an object, an array, etc…).</li></ul><pre>let obj = {}; //Empty new object<br>obj[{ &quot;ex&quot;: 2 }] = 3; <br><strong><em>// </em>This is not aplicable<em>. In object key-feild only allow </em></strong>integer, strings, and symbols<strong><em>. In Value field any data type will be allow.</em></strong></pre><pre>let map = new Map(); //Empty new map<br>map.set({ &quot;ex&quot;: 2 }, 3); <br><strong><em>// </em>This is aplicable<em>. In map you can use any data type as key and value</em></strong></pre><p>There are three ways to create a new Empty Object :</p><blockquote>let variable = {};//<strong><em>using Brackets</em></strong>(1- step)</blockquote><blockquote>var obj = new Object();<strong><em> //by constructor </em></strong><em>(2- step)</em></blockquote><blockquote>var obj = new Object; //same result</blockquote><blockquote>var obj = Object.create(null); <strong><em>//by using Object.prototype.create </em></strong><em>(3- step)</em></blockquote><h3>Accessing element</h3><p><strong>Map :</strong></p><p><em>Map.prototype.get(key)</em></p><pre>map.get(<em>key</em>)// value</pre><p><strong>Object :</strong></p><p><em>Object.&lt;key&gt;</em> and<em> Object[‘key’]</em></p><pre>obj.key //value<br>obj[&#39;<em>key</em>&#39;] //value</pre><h3>Adding new element</h3><p><strong>Map :</strong></p><p><em>Map.prototype.set()</em></p><pre>map.set(&quot;key&quot;,&quot;value&quot;); //{1=&gt;2, 2=&gt;3, &quot;key&quot;=&gt;&quot;value&quot;}</pre><blockquote>But if you pass an <em>existing key</em>, it will <strong><em>overwrite</em></strong> the value mapped to that key with the new value</blockquote><p><strong>Object :</strong></p><p><em>Object.&lt;key&gt; = value</em></p><p><em>Object[‘key’] = value</em></p><pre>obj[&#39;grade&#39;] = &#39;passs&#39;; //{id: 1, gender: &quot;male&quot;}<br>obj.gender = &#39;fail&#39;;</pre><blockquote>Both is ok and will <strong>overwrite</strong> the existing mapped value if property already exists.</blockquote><pre>let person = {<br>name: &#39;Rayan&#39;,<br><strong>age: 20,<br>strength: 100</strong><br>}</pre><pre>let warrior = {<br><strong>age: 36,<br>strength: 1500</strong><br>}</pre><pre><em>//I am going to assign </em><strong><em>warrior</em></strong><em> Object to </em><strong><em>person</em></strong><em> Object<br></em>let myworrior = Object.assign(person, warrior);<br>console.log(myworrior);</pre><pre>OUTPUT : { name: &#39;Rayan&#39;,<strong> age: 36, strength: 1500</strong> }<br>// Did you see that, warrior object values overwrite person object values via using same key-feild.</pre><h3>Let`s solve the problem.</h3><p>We have to write a program to count and display the number of repetitions in each letter in a sentence.</p><p>we can solve this problem using a <strong>map</strong> and <strong>object</strong>.</p><pre>let word = &quot;These days I am studying&quot;;</pre><ol><li>First, you need to remove spaces and put each letter into a new array.</li></ol><pre>const wordArry = Array.from(word.replace(/ /g, &#39;&#39;));</pre><p>2. Then, you can remove each duplicate letter and put it into a new <strong>map</strong> or <strong>Object</strong>.</p><blockquote>Object :</blockquote><pre><strong>Input :</strong> <br>wordArray : [&#39;I&#39;, &#39;T&#39;, &#39;a&#39;, &#39;a&#39;, &#39;d&#39;,&#39;d&#39;, &#39;e&#39;, &#39;e&#39;, &#39;g&#39;, &#39;h&#39;,&#39;i&#39;, &#39;m&#39;, &#39;n&#39;, &#39;s&#39;, &#39;s&#39;,&#39;s&#39;, &#39;t&#39;, &#39;u&#39;, &#39;y&#39;, &#39;y&#39;]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efd3d8a0191fa9ff83effd0bef954a44/href">https://medium.com/media/efd3d8a0191fa9ff83effd0bef954a44/href</a></iframe><pre><strong><em>Result will be like this :</em></strong><br>{T: 1,h: 1,e: 2,s: 3,d: 2,a: 2,y: 2,I: 1,m: 1,t: 1,u: 1,i: 1,n: 1,g: 1}</pre><blockquote>Map :</blockquote><pre><em>//create new Empty Map object</em><strong><br>var mapAllRepition = new Map();</strong></pre><pre><em>// then, loop </em><em>for i = 0 to stringArr.length</em><em> do<br>// you can access array element using i<br></em><strong>for (let i = 0; i &lt; stringArr.length; i++) {                mapAllRepition.set(</strong><strong>wordArry[i], (mapAllRepition.get(</strong><strong>wordArry[i]) || 0) + 1);           <br>}</strong></pre><pre>//now apply previous same logic when adding element <br>// if same element come again and again every time add 1 and increse value using overwite feture in object and map.</pre><p>Source Code :</p><p><a href="https://github.com/sriThariduSangeeth/RAPID-T4-CL-with-Krish">sriThariduSangeeth/RAPID-T4-CL-with-Krish</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a22bd9fd6a16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to Postgres with PostGraphile in NestJS]]></title>
            <link>https://dtsangeeth.medium.com/intro-to-postgres-with-postgraphile-in-nestjs-c0713442fc6?source=rss-4761ca2543e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0713442fc6</guid>
            <category><![CDATA[postgraphile]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Dilan Tharidu Sangeeth]]></dc:creator>
            <pubDate>Fri, 14 May 2021 08:26:01 GMT</pubDate>
            <atom:updated>2021-05-30T14:31:30.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="NodeJs — NestJS back end server" src="https://cdn-images-1.medium.com/max/1024/1*dHYsHqZ_XLcCutiHaMZtIA.png" /><figcaption>Backend sample Application</figcaption></figure><p>Source code :</p><p><a href="https://github.com/sriThariduSangeeth/Vehicle-Nest-NodeJS-Backend">sriThariduSangeeth/Vehicle-Nest-NodeJS-Backend</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0713442fc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>