<?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: csamanta95</title>
    <description>The latest articles on DEV Community by csamanta95 (@csamanta95).</description>
    <link>https://dev.to/csamanta95</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%2F332018%2F981f1175-5956-478f-84cc-7ffb8220bfd8.png</url>
      <title>DEV Community: csamanta95</title>
      <link>https://dev.to/csamanta95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/csamanta95"/>
    <language>en</language>
    <item>
      <title>           Arrow Functions in JavaScript for Beginners </title>
      <dc:creator>csamanta95</dc:creator>
      <pubDate>Tue, 25 Feb 2020 03:28:19 +0000</pubDate>
      <link>https://dev.to/csamanta95/arrow-functions-in-javascript-for-beginners-478n</link>
      <guid>https://dev.to/csamanta95/arrow-functions-in-javascript-for-beginners-478n</guid>
      <description>&lt;p&gt;A function is a subprogram designed to perform a particular task. Functions combined, become the main “building blocks” of the program.&lt;br&gt;&lt;br&gt;
JavaScript has many built-in/ anonymous functions. We can create functions of our own as well.&lt;/p&gt;

&lt;p&gt;Arrow functions, introduced in the latest version of JavaScript ES6, provides a concise way to write functions in JavaScript. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vDIgXuzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/pZio0Wjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vDIgXuzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/pZio0Wjl.png" alt="ES5 vs 6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Var", which is a way to declare a variable, is used in ES5. Functions are written using the "function" keyword with arguments. These functions have existed since the beginning of JavaScript.&lt;/p&gt;

&lt;p&gt;ES6 allows you to declare a variable using "const" and "let". Arrow functions can be used, making writing code shorter! The same code(top) can be written shorter with the arrow method (bottom). As shown in the diagram, a lot of the syntax required in ES5 is optional for the ES6 arrow method. The parenthesis is optional when there is one argument, and the braces and keyword "return" are optional.  &lt;/p&gt;

&lt;p&gt;Named Functions into Arrow functions:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example 1&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1i2jBHDK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/000UuHWh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1i2jBHDK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/000UuHWh.png" alt="ES5 1st function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is a regular function (ES5). The function takes a name "message" and returns "Green Light District". When we "console.log(message())", the message shows up in the console. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KmA1V8na--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ag5C8xSh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KmA1V8na--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ag5C8xSh.png" alt="ES5 1st function in Arrow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is the same function, using the arrow method. It has the same output but shorter code! In order to change the first function into an arrow function, the function name has to be turned into a variable. The arrow is created with the equal sign and greater than symbol, "=&amp;gt;". The string "Green Light District" is being returned implicitly after the arrow symbol.    &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example 2&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uCAKfnvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/LpPOsbHl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uCAKfnvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/LpPOsbHl.png" alt="ES5 2nd function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another function that takes in an argument and interpolates the argument with a string in the result. Below is the function turned into an arrow function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oavaWN7A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ABkPZ3gl.png%3F1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oavaWN7A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ABkPZ3gl.png%3F1" alt="ES6 2nd function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example 3&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9eaFWqIs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/AXvVMxXl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9eaFWqIs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/AXvVMxXl.png" alt="ES6 3rd function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function above is an arrow function taking in two arguments. There will be two argument within the parenthesis, after the variable is declared. Both "a" and "b" will be interpolated after the arrow sign.  &lt;/p&gt;

&lt;p&gt;As I mentioned before, JavaScript has many built-in or anonymous functions. These functions can also be written as arrow functions. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZxyveqC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/IYsLPl3h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZxyveqC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/IYsLPl3h.png" alt="ES6 4th function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As an arrow function:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kH6pNcoV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/UOKn5tYh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kH6pNcoV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/UOKn5tYh.png" alt="ES6 4th function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given an array of objects, the .map method can be used to take in an array of numbers and creates a new array containing the return value of your choice. &lt;/p&gt;

&lt;p&gt;This arrow function, as the others above have replaced the "function" keyword effectively with the arrow "=&amp;gt;" and had optional syntax's, making concise code. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>functions</category>
      <category>es6</category>
    </item>
    <item>
      <title>A Short Intro to Algorithms </title>
      <dc:creator>csamanta95</dc:creator>
      <pubDate>Mon, 10 Feb 2020 18:26:05 +0000</pubDate>
      <link>https://dev.to/csamanta95/a-short-intro-to-algorithms-1h63</link>
      <guid>https://dev.to/csamanta95/a-short-intro-to-algorithms-1h63</guid>
      <description>&lt;p&gt;An algorithms in the simplest definition is a solution to a problem. Algorithms are a set of guidelines that describe how to solve a problem and perform a task. &lt;/p&gt;

&lt;p&gt;A great place to start is by learning the search and sorting algorithms. The linear sort is one the simplest search algorithms. The algorithm below is the linear search: compares the key (item to find) to each item in a list until it has been found. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L4xuhSBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JbFK7i8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L4xuhSBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JbFK7i8.jpg" alt="Linear Sort in Ruby"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3mqqt-hH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gTYZjEq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3mqqt-hH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gTYZjEq.png" alt="Linear Sort in Ruby"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What the algorithm is doing: &lt;br&gt;
1) The method "linear_search" takes in an array and a key. The key is the item you’re looking for. The algorithm starts from the leftmost element of the array and one by one compares the element we are searching for with each element of the array.&lt;br&gt;
2) If the key is not found, a message is returned.&lt;br&gt;
3) If the key is found, a message is printed out stating the key and the index.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TctEvscJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0WiRE1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TctEvscJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0WiRE1u.png" alt="Linear Sort in Ruby: Solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. The algorithm below is the bubble sort: sorts an array in ascending order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JBITVdme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gsFc7Yv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JBITVdme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gsFc7Yv.jpg" alt="Bubble Sort in Ruby: Solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MdQtCy6t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BbpBiNv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MdQtCy6t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BbpBiNv.png" alt="Bubble Sort in Ruby: Solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What the algorithm is doing: &lt;br&gt;
1) The method "bubbleSort" takes in a single array parameter. &lt;br&gt;
2) A variable "n" finds the array length. Bubble sort needs to know the length in order to know how many times to iterate through the array.&lt;br&gt;
3) The "loop do" will loop through then iterate through each element of the array. With "loop do" in ruby, you need to tell the method when to stop. The sentinel variable "swapped" will let the loop know when to stop. Swapped = false is set in the beginning since immediately after the beginning of your loop, there have been no swaps. Swapped will break when it can no longer be true (there are no more swapping needed). The loop will run as long as the swap is true. &lt;br&gt;
4)The loop will check if element i is greater than the element next to it i + 1. If it is, it will swap the value of i with the value of i+1. The loop will also set the value of swapped to true when there is a swap made.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sfE7lVmv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/M9fJAfS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sfE7lVmv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/M9fJAfS.png" alt="Bubble Sort in Ruby: Solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5)The loop will terminate when there is no more swaps needed and the array will be returned in ascending order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YFNDuaPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/EEM9awH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YFNDuaPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/EEM9awH.png" alt="Bubble Sort in Ruby: Solution"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
