<?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 Camilo Andres Parra on Medium]]></title>
        <description><![CDATA[Stories by Camilo Andres Parra on Medium]]></description>
        <link>https://medium.com/@caparra92?source=rss-91540546be41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fK6koNZ-Tipbc2FcACEJaA.jpeg</url>
            <title>Stories by Camilo Andres Parra on Medium</title>
            <link>https://medium.com/@caparra92?source=rss-91540546be41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 02:25:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@caparra92/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[Building a basic chat terminal app with Python using Sockets and Multithreading (Part 1)]]></title>
            <link>https://medium.com/@caparra92/building-a-basic-chat-terminal-app-with-python-using-sockets-and-multithreading-part-1-aa96cd4678b9?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa96cd4678b9</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tcp-ip]]></category>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 21:19:02 GMT</pubDate>
            <atom:updated>2024-11-27T03:27:48.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlWW-1h1d-CVQmOx0j2AdA.png" /><figcaption>Computers communicating between each other</figcaption></figure><h3><strong>If you like my work, this is how you can buy me a coffee!</strong></h3><figure><a href="https://buymeacoffee.com/caparra92"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4ajjFwLjKin4nxFuxFhkQ.png" /></a></figure><p>Before starting to code, as many tutorials on the internet do, I want to give you a bit of context about this topic. To begin with, let’s talk about some key concepts related to this post. <strong>Part 1 </strong>covers the key concepts and the app details, and <strong>Part 2</strong> will be focused on explaining the coding aspects.</p><p><strong>What is a socket?</strong></p><p>The IBM website defines a <a href="https://www.ibm.com/docs/en/i/7.3?topic=communications-socket-programming"><em>socket </em></a>as a “communications connection point” (final point), which can be nominated and redirected in a network. In simple words, they are a fundamental resource in the development of networking applications as they allow communication between two points in one or many networks.</p><p><strong>Socket types</strong></p><p>They are classified by messaging fidelity and order. The most common socket families are:</p><ul><li><strong>SOCKET_STREAM</strong>: Defines a connection-oriented service (TCP).</li><li><strong>SOCK_DGRAM</strong>: Defines a connectionless service (UDP).</li><li><strong>SOCK_RAW</strong>: Allows access to lower layer protocols (IP or ICMP).</li></ul><p>Those families are registered in different domains called address families as follows:</p><ul><li><strong>UNIX</strong>: Defines the address families AF_UNIX</li><li><strong>Internet</strong>: Specifies the address family AF_INET and requires (TCP/IP) protocol installed in the system.</li><li><strong>NDD</strong>: Defines the address family AF_DD</li></ul><p>Now it’s time to start coding!</p><p>We will build a terminal chat application using an oriented-connection protocol and the client-server model.</p><p>The server creates a socket and listens to a specific port while waiting for client connections. Clients should connect at the same IP-Port as the server.</p><p>The socket family will be <strong>SOCKET_STREAM </strong>and <strong>AF_INET </strong>as the address family. For Windows users, TCP/IP is installed by default in Windows 10.</p><p>We will use localhost with the IP <strong>127.0.0.1 </strong>and the <strong>5000 </strong>port (commonly used for networking applications).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*6iVQaa8fILmyU66bWTsWhA.png" /><figcaption>Client-Server connection using sockets</figcaption></figure><p><strong>Source code</strong></p><p><strong>Server</strong></p><p>As mentioned in the title, we will use Python along with a few libraries in order to allow our server to create and listen for socket connections. We import the <strong>socket </strong>library and <strong>threading </strong>for multithreading processes. In addition, the <strong>JSON</strong> library allows us to parse messages and convert them into Python dictionaries.</p><pre>import socket<br>import json <br>import threading</pre><p>Our server.py file will have 4 functions:</p><ul><li><strong>start_server</strong>: To instantiate the socket object and assign IP-Port values.</li><li><strong>broadcast_message</strong>: To send a message from the server to all clients (broadcast)</li><li><strong>target_message</strong>: To send a message to a specific client using the client_id value.</li><li><strong>handle_clients</strong>: Assign an individual <strong>client_id </strong>and manages message sending using the target_message or broadcast_mesage depending on the purpose.</li></ul><pre>def start_server(ip, port): <br><br>def broadcast_message(message,sender_socket):<br><br>def target(message, target_id):<br><br>def handle_clients(client_socket, addr, connected_clients):</pre><p><strong>Client</strong></p><p>Our client.py file will have 2 functions:</p><ul><li><strong>start_client</strong>: Instantiates the socket object and connects to the server IP-Port.</li><li><strong>receive_mesage</strong>: Gets the client socket instance as parameter to decode the messages sent by the server.</li></ul><pre>def start_client(ip, port, username): <br><br>def receive_message(client_socket):</pre><p>For further reading about socket objects in Python, I recomend the official <a href="https://docs.python.org/3/library/socket.html#socket-objects"><em>docs </em></a>to get to know about other methods.</p><p>I hope it can be helpful, the full code will be available in <strong>Part 2</strong>.</p><p>Thank you.</p><p><strong>References</strong></p><ul><li><a href="https://docs.python.org/3/library/socket.html#socket-objects">https://docs.python.org/3/library/socket.html#socket-objects</a></li><li><a href="https://www.ibm.com/docs/en/i/7.3?topic=communications-socket-programming">https://www.ibm.com/docs/en/i/7.3?topic=communications-socket-programming</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa96cd4678b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a basic Hash Table with plain JavaScript]]></title>
            <link>https://medium.com/@caparra92/creating-a-basic-hash-table-with-plain-javascript-109913afc6c9?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/109913afc6c9</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[hash-table]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 03:33:55 GMT</pubDate>
            <atom:updated>2024-01-19T03:33:55.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/385/0*WcBrlTQMIh5Vs7_X" /></figure><p>One of the more useful data-structures in computer science is the hash table, also known as hash map in some programming languages. They store key-value pairs and computes the indexes with a function called hash code. In this article I will explain how to implement a basic hash table in order to understand how indexes are calculated and how to represent the main operations such as insertion, searching and deletion.</p><p>When learning a new concept (not only in programming but also in general) I try to represent this topic in the simplest way I can do, so I can extend it later on if I need a sophisticated version of that thing. That’s exactly what I am looking for in this article, to explain it in the most basic possible way as I would have liked to learn some time ago.</p><p>To begin with, let’s say that a hash table is quite famous for its powerful performance in insertion or searching. Commonly used for database indexing or set implementation.</p><p>As we represented other data-structures in this series, I will use the concept of classes of ES6 Javascript version that I consider more readable.</p><p>Our hash table class looks like this:</p><pre>class HashTable {<br>  constructor() {<br>    // Initialize the hash table with an array of a fixed size.<br>    this.hashTable = new Array(50);<br>  }<br>}</pre><p>It is important to initialize a fixed array because one of the considerations about hash tables is the memory usage. This is one of the concerns we need to consider when implementing this data-structure instead of arrays</p><p>There are many ways to implement the hash code function and, in this case, I use the sum of char values using the charCodeAt function in Javascript.</p><pre>hashCode(key) {<br>    let sumOfCharValues = 0;<br>    for(let i = 0; i &lt; key.length; i++) {<br>      sumOfCharValues += key.charCodeAt([i]);<br>    }<br>    let index = sumOfCharValues % 50;<br>    return index;<br>  }</pre><p>We simply loop through the keys and retrieve the char code of every letter assuming we have strings stored as values. Finally, we create the index applying the modulo operation between our sumOf CharValues and a prime number equals to my array size in order to add uniqueness to our hashing method (<em>You can find most of these implementations using 31 prime number as modulo</em>).</p><p>As I said before, the goal with hash functions is to generate unique number indexes so, in our example if we apply the hash function to the string “<strong>name</strong>” it will return:</p><ul><li>n =&gt; 110</li><li>a =&gt; 97</li><li>m =&gt; 109</li><li>e =&gt; 101</li></ul><p>Sum of char values = 417</p><p>Index returned = 417 % 50 =&gt; 17</p><p>So 17 is the index for our key-value pair.</p><p>With the hash code function solved, the remaining operations become easier to implement because they probably will use the hashCode function to find the element we need to retrieve or delete as an example.</p><p>For instance, the “insertion” operation, called ‘put ’ in our class:</p><pre>put(key, value) {<br>    let index = this.hashCode(key);<br>    this.hashTable[index] = value;<br> }</pre><p>We compute the index and insert it at that position in our fixed array.</p><p>The get method retrieves a value based on the key passed as argument:</p><pre>get(key) {<br>    let index = this.hashCode(key);<br>    <br>    return this.hashTable[index];<br> }</pre><p>The last two methods for the hash table class are remove and contains, we use the last method to validate if a key is present into the hash table by using its hashCode.</p><pre> remove(key) {<br>    let index = this.hashCode(key);<br>    // Remove the key-value pair with the given key from the hash table.<br>    this.hashTable[index] = undefined;<br>  }</pre><p>Assign the value to undefined is the simplest way to delete considering that all unused positions in a Javascript array are undefined by default.</p><p>The following is the code for the contains method:</p><pre>contains(key) {<br>    // Return true if the hash table contains the given key, false otherwise.<br>    let index = this.hashCode(key);<br>    <br>    return this.hashTable[index] !== undefined;<br> }</pre><p>Now we are done! This is the basic hash table I wanted to share but, before finish, it’s time to test the class.</p><pre>// Example usage:<br>const hashTable = new HashTable();<br>hashTable.put(&quot;name&quot;, &quot;Alice&quot;);<br><br>hashTable.put(&quot;age&quot;, 25);<br>console.log(hashTable.get(&quot;name&quot;)); // Should print &quot;Alice&quot;<br>console.log(hashTable.contains(&quot;city&quot;)); // Should print false<br>hashTable.remove(&quot;age&quot;);<br>console.log(hashTable.contains(&quot;age&quot;)); // Should print false</pre><p>As mentioned in previous posts, this is just the basic concept which certainly can be improved and refactored, taking into consideration that sometimes two keys can reflect the same hash code called as “<strong><em>Collisions</em></strong>” which is not covered in this article.</p><p>For further reading about hash table collisions, I recomend the following article in <a href="https://www.geeksforgeeks.org/hash-table-data-structure/">GeeksForGeeks</a>.</p><p>I hope it can be helpful, the full code is available on <a href="https://codepen.io/caparra92/pen/vYbLXbY">CodePen</a>.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=109913afc6c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a basic linked list with plain JavaScript]]></title>
            <link>https://medium.com/@caparra92/creating-a-basic-linked-list-with-plain-javascript-3ab703c48985?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ab703c48985</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 04:02:05 GMT</pubDate>
            <atom:updated>2024-01-08T04:02:05.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*vcuG7xou5l7pb8VVMqaS7A.png" /></figure><p>Happy new year everyone!</p><p>I hope everything is good and all your purposes will be achieved in 2024.</p><p>This is the first story of 2024 and I want to continue the “Data structures series” remembering that we already posted 2 stories about Stacks and Queues so if you do not read them yet check them out to introduce you in the concept of data structures.</p><p>Linked list are a very particular data structure as they can be presented in different forms:</p><ul><li>Simple linked list</li><li>Double linked list</li><li>Circular linked list</li></ul><p>I will explain each one in detail. Before that, we need to consider 3 aspects about linked lists components:</p><ul><li><strong>Node</strong>: Contains the data element</li><li><strong>Next</strong>: Reference to the next node</li><li><strong>Head</strong>: First node in the linked list</li></ul><p>Now let’s implement our basic linked list with Javascript:</p><p>First of all we need the Node representation, I wil use a class so we can imported and apply code reusability if necessary (with other data-structures implementations).</p><pre>class Node {<br>  constructor(value) {<br>    this.value = value<br>    this.next = null<br>  }<br>}</pre><p>I initialize the next property with null as we do not have any next element at the beginning.</p><p>Next, it is the turn to the linked list class:</p><pre>class LinkedList {<br>  constructor() {<br>    this.head = new Node()<br>  }<br>}</pre><p>The head of the linked list is a Node instance so we have access to the value and next properties.</p><p>The first operation in the LinkedList class is insertion.</p><pre>insert(value) {<br>    let current = this.head<br>    // Insert a new node with the given value at the end of the list.<br>    const node = new Node(value)<br>    if(!this.head) {<br>      this.head = node<br>    } else {<br>      current = this.head<br>      while(current.next) {<br>        current = current.next<br>      }<br>    }<br>    current.next = node<br>  }</pre><p>We use a <strong>current </strong>value with a reference of the head (First Node) and the next step is to create a new Node instance. If the head is null, we assign the Node to be the head, if not, we use the current element to walk through every Node using the next property and then, assign the new node.</p><p>The second basic operation is deletion as follows:</p><pre>delete(value) {<br>    if(!this.head) {<br>      return<br>    } <br>    let current = this.head<br>    let previous = null<br>    while(current) {<br>      if(current.value === value) {<br>        previous.next = current.next<br>        return<br>      }<br>      previous = current<br>      current = current.next<br>    }<br>  }</pre><p>Using the same principle, we can validate if we have a head and then, we create the current reference to the head element. For deletion it is necessaty to consider the previous element and not only the next. This strategy help us to “jump” the Node to be deleted and link the previous and next Node elements if the value we passed to the method matches with the current.value in the linked list.</p><p>The next one is the search method:</p><pre>search(value) {<br>    let current = this.head<br>    // Return true if the value is in the list, false otherwise.<br>    while(current.next) {<br>      current = current.next<br>      if(current.value === value) {<br>        return true<br>      }<br>    }<br>    return false<br>  }</pre><p>We need to walk through every element and validate if the value we passed matched with the current.value element (like in deletion). At the end, we returned true or false depending on the success or fail of the operation.</p><p>The last method is a helper method but not completely necessary. It will return an array representation of the data-structure when we printed to the console.</p><p>The following is the toArray method:</p><pre>toArray() {<br>    let current = this.head<br>    const arr = []<br>    while(current.next){<br>      current = current.next<br>      arr.push(current.value)<br>    }<br>    return arr<br>  }<br>}</pre><p>We apply the same principle (Loop the linked list with the current value) to assign every value to the empty array using the push native array method. Finally we return the array.</p><p>Now we can do some simple tests to veryfy our linked list:</p><pre>// Example usage:<br>const linkedList = new LinkedList()<br>linkedList.insert(1);<br>linkedList.insert(2);<br>linkedList.insert(3);<br>linkedList.insert(4);<br>linkedList.insert(5);<br>linkedList.insert(6);<br>linkedList.insert(7);<br>console.log(linkedList.toArray()); // Should print [1, 2, 3]<br>linkedList.delete(5);<br>console.log(linkedList.toArray()); // Should print [1, 3]<br>console.log(linkedList.search(3)); // Should print true</pre><p>This is the full code of the class implementation:</p><pre>class Node {<br>  constructor(value) {<br>    this.value = value<br>    this.next = null<br>  }<br>}<br><br>class LinkedList {<br>  constructor() {<br>    this.head = new Node()<br>  }<br>  <br>  insert(value) {<br>    let current = this.head<br>    // Insert a new node with the given value at the end of the list.<br>    const node = new Node(value)<br>    if(!this.head) {<br>      this.head = node<br>    } else {<br>      current = this.head<br>      while(current.next) {<br>        current = current.next<br>      }<br>    }<br>    current.next = node<br>  }<br><br>  delete(value) {<br>    if(!this.head) {<br>      return<br>    } <br>    let current = this.head<br>    let previous = null<br>    while(current) {<br>      if(current.value === value) {<br>        previous.next = current.next<br>        return<br>      }<br>      previous = current<br>      current = current.next<br>    }<br>  }<br><br>  search(value) {<br>    let current = this.head<br>    // Return true if the value is in the list, false otherwise.<br>    while(current.next) {<br>      current = current.next<br>      if(current.value === value) {<br>        return true<br>      }<br>    }<br>    return false<br>  }<br><br>  toArray() {<br>    let current = this.head<br>    const arr = []<br>    while(current.next){<br>      current = current.next<br>      arr.push(current.value)<br>    }<br>    return arr<br>  }<br>}<br><br>// Example usage:<br>const linkedList = new LinkedList()<br>linkedList.insert(1);<br>linkedList.insert(2);<br>linkedList.insert(3);<br>linkedList.insert(4);<br>linkedList.insert(5);<br>linkedList.insert(6);<br>linkedList.insert(7);<br>console.log(linkedList.toArray()); // Should print [1, 2, 3]<br>linkedList.delete(5);<br>console.log(linkedList.toArray()); // Should print [1, 3]<br>console.log(linkedList.search(3)); // Should print true</pre><p>Congratulations! This can be improved a lot adding some other important operations but with this basic template you can understand the first steps of the linked list data-structure and, the most important thing, made with plain javascript.</p><p>I hope it can be helpful, you can find the full code upload in <a href="https://codepen.io/caparra92/pen/qBLygby">CodePen</a>.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ab703c48985" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a basic queue with plain JavaScript]]></title>
            <link>https://medium.com/@caparra92/creating-a-basic-queue-with-plain-javascript-b96514eff61c?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/b96514eff61c</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[stacks-queues]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Thu, 14 Dec 2023 00:28:34 GMT</pubDate>
            <atom:updated>2023-12-24T02:10:45.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PE09ZxkNQDC_paVCDXW_0g.png" /></figure><p>Continuing with the data-structures series, today I will discuss another basic implementation that I hope you will find interesting.</p><p>Last time I talked about stacks which implements LIFO pattern (Last in, first out), so in this case, the queue uses the FIFO pattern (First in, first out).</p><p>Consider this about the difference between stacks and queues.</p><figure><img alt="Stack versus Queue" src="https://cdn-images-1.medium.com/max/880/0*FY7ULI1ot-e5NlD5.png" /></figure><p>For the queues you need to consider two main operations: Enqueue and Dequeue.</p><p>To start with, we will create a simple class called queue</p><pre>class Queue {<br>  constructor() {<br>    // Initialize an empty array to represent the queue.<br>    this.queue = []<br>  }</pre><p>We initialize our object with an empty array so we can execute some operations over this.</p><p>First of all, for validation purposes we can create a method to check if the queue is empty.</p><pre>isEmpty() {<br>    // Return true if the queue is empty, false otherwise.<br>    return this.queue.length === 0<br>  }</pre><p>Next, for the enqueue method, we receive an item to enqueue and validate if we already have items in our queue (if it is empty), if not we loop over the queue from the front to the rear and move the existing items 1 place to the left (this.queue[i] = this.queue[i-1]) so the new item is placed in the rear.</p><pre> enqueue(item) {<br>    // Add the item to the rear of the queue.<br>    <br>    if(this.isEmpty()){<br>      this.queue[0] = item<br>    } else {<br>      for(let i = this.queue.length; i &gt; 0; i--) {<br>        this.queue[i] = this.queue[i-1]<br>      }<br>      this.queue[0] = item<br>    }<br>    <br>  }</pre><p>The dequeue method works almost the same as the previous one but we can perform 2 more operations. The first one is the deletion of the item at the front of the queue with deleted = this.queue[this.queue.length-1]. We declared an empty array which will contain our queue minus the deleted item. After this, we have to move our items to the left as berfore and then loop left to right to assingn the remaining items to our temp array.</p><pre>dequeue() {<br>    // Remove and return the item from the front of the queue.<br>    let temp = []<br>    const deleted = this.queue[this.queue.length-1]<br>    <br>    for(let i = this.queue.length -1; i &gt; 0; i--){<br>      this.queue[i] = this.queue[i-1]<br>    }<br>    <br>    for(let i = 0; i &lt; this.queue.length; i++) {<br>      if(this.queue[i] !== undefined) {<br>        temp.push(this.queue[i])<br>      }<br>    }<br>    this.queue = temp<br>      <br>     return deleted<br>  }</pre><p>Finally we return the deleted item.</p><p>And that’s it! Now your queue is ready to perform operations such as enqueue and dequeue. Some implementations also have a peek method to return the item at the front of the queue.</p><pre>peek() {<br>    // Return the item at the front of the queue.<br>    return this.queue[this.queue.length-1]<br>  }</pre><p>The entire code will be looking like this:</p><pre>class Queue {<br>  constructor() {<br>    // Initialize an empty array to represent the queue.<br>    this.queue = []<br>  }<br><br>  enqueue(item) {<br>    // Add the item to the rear of the queue.<br>    <br>    if(this.isEmpty()){<br>      this.queue[0] = item<br>    } else {<br>      for(let i = this.queue.length; i &gt; 0; i--) {<br>        this.queue[i] = this.queue[i-1]<br>      }<br>      this.queue[0] = item<br>    }<br>    <br>  }<br><br>  dequeue() {<br>    // Remove and return the item from the front of the queue.<br>    let temp = []<br>    const deleted = this.queue[this.queue.length-1]<br>    <br>    for(let i = this.queue.length -1; i &gt; 0; i--){<br>      this.queue[i] = this.queue[i-1]<br>    }<br>    <br>    for(let i = 0; i &lt; this.queue.length; i++) {<br>      if(this.queue[i] !== undefined) {<br>        temp.push(this.queue[i])<br>      }<br>    }<br>    this.queue = temp<br>      <br>     return deleted<br>  }<br><br>  peek() {<br>    // Return the item at the front of the queue.<br>    return this.queue[this.queue.length-1]<br>  }<br><br>  isEmpty() {<br>    // Return true if the queue is empty, false otherwise.<br>    return this.queue.length === 0<br>  }<br>}<br><br>// Example usage:<br>const queue = new Queue();<br>queue.enqueue(1);<br>queue.enqueue(2);<br>queue.enqueue(3);<br>console.log(queue.dequeue()); // Should print 1<br>console.log(queue.peek()); // Should print 2<br>console.log(queue.isEmpty()); // Should print false</pre><p>Now we’re done, I hope this could be helpful if you are interested in javascript and data structures as I am.</p><p><strong>Congratulations</strong>! Now your are able to reproduce queues data structures with your favorite programming language.</p><p>In upcoming posts I will cover the “Linked List” implementation to continue with the data structure learning.</p><p>If you’d like to see the online implementation, I have posted the entire code on <a href="https://codepen.io/caparra92/pen/VwgvBpQ">codePen</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b96514eff61c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a basic stack with plain JavaScript]]></title>
            <link>https://medium.com/@caparra92/creating-a-basic-stack-with-plain-javascript-ea725cf2437c?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea725cf2437c</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Fri, 27 Oct 2023 21:56:23 GMT</pubDate>
            <atom:updated>2023-10-27T21:56:23.852Z</atom:updated>
            <content:encoded><![CDATA[<p>Data structures are so important in computer science since we use them everyday. Think about the windows file explorer or the browser history, both rely on data structures such as stacks or linked lists. A real-life example of this is stack of books when we always add a new book at the top of the stack which is a push operation, if we want to remove a book, we remove the book on the top, that means a pop operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*WVaN9apb-eu3kiXOR97Qig.png" /><figcaption>From Wikimedia Commons, the free media repository</figcaption></figure><p>When you press the “go back” button in your prefered browser you are applying one of the stack operations called “pop”. But, what does it means? I will cover a little explanation so do not worry about it. The basic stack operations are push, pop, and peek.</p><p>In this short post I will guide you through the stack implementation, one of the commonly used and basic data structures. JavaScript native implementations provided by the language and I’m 99% sure that you’ve used them extensively a lot if you have JS experience, these are the famous “Arrays”. Yes, they have a stack implementation and performs the basic operations called “push” (<em>Adding an item at the top of the stack</em>) and “pop” (r<em>eturning and deleting the last item of the stack</em>).</p><p>Now that we know a little bit more about stacks let’s start with the basic methods.</p><p>Let’s start by creating a stack class with a constructor method.</p><pre>class Stack {<br>    constructor() {<br>      // Initialize an empty array to represent the stack.<br>      this.stack = []<br>    }<br>}</pre><p>We have initialized our stack with an empty value as starting point.</p><p>Now, the first method is the push method, similar to the push array method. The implementation is simple, we need to pass the new item as an argument to the function and it will be assign at the top of the stack (<em>this.stack[this.stack.length]</em>)</p><pre>push(item) {<br>  this.stack[this.stack.length] = item<br>}</pre><p>For the pop method it needs to return and delete the last item in the stack. In this case I assigned the last item reference in a variable called “deleted” to be returned after the array modification. Also, we need another array to copy the elements and the “magic” part will be the item deletion. For this implementation, I created a for loop to run backwards on the array (<em>i = this.queue.length -1</em>) and move the element positions to the left. After this step we will have the same array with the same length and the last item being undefined as we moved the elements from right to left. Finally, I have created another for loop (<em>It could be implemented with just one but as you know it is a basic implementation</em>) to “clean” the undefined position and, at the end we need to assign the new array called “temp” to our stack array.</p><pre>pop() {<br>  let temp = []<br>  let deleted = this.stack[this.stack.length-1]<br>  //Move the elements from right to left<br>  for(let i = this.stack.length-1; i &gt;= 0;i--){<br>    this.stack[i] = this.stack[i-1]<br>  }<br>  //Clean the undefined item positions<br>  for(let i = 0; i &lt; this.stack.length; i ++){<br>    if (this.stack[i] !== undefined) {<br>      temp.push(this.stack[i])<br>    }<br>  }<br>  this.stack = temp<br>  return deleted<br>}</pre><p>Our next method is called peek which just returns the last item in our stack.</p><pre>peek() {<br>  // Return the item at the top of the stack.<br>  let top = this.stack[this.stack.length-1]<br>  return top<br>}</pre><p>The last method of our basic implementation is a boolean method for identifying if the stack is empty <em>(true</em>) or not (<em>false</em>).</p><pre>isEmpty() {<br>  // Return true if the stack is empty, false otherwise.<br>  return stack.length === 0<br>}</pre><p>At this point, you are prepared to test yor stack class with some examples, let’s try a few.</p><pre>  // Example usage:<br>const stack = new Stack();<br>stack.push(1);<br>stack.push(2);<br>stack.push(3);<br>console.log(stack.pop()); // Should print 3<br>console.log(stack.peek()); // Should print 2<br>console.log(stack.isEmpty()); // Should print false</pre><p>The entire code will be looking like this:</p><pre>class Stack {<br>    constructor() {<br>      // Initialize an empty array to represent the stack.<br>      this.stack = []<br>    }<br>  <br>    push(item) {<br>      this.stack[this.stack.length] = item<br>    }<br>  <br>    pop() {<br>      let temp = []<br>      let deleted = this.stack[this.stack.length-1]<br>      //Move the elements from right to left<br>      for(let i = this.stack.length-1; i &gt;= 0;i--){<br>        this.stack[i] = this.stack[i-1]<br>      }<br>      //Clean the undefined item positions<br>      for(let i = 0; i &lt; this.stack.length; i ++){<br>        if (this.stack[i] !== undefined) {<br>          temp.push(this.stack[i])<br>        }<br>      }<br>      this.stack = temp<br>      return deleted<br>    }<br>  <br>    peek() {<br>      // Return the item at the top of the stack.<br>      let top = this.stack[this.stack.length-1]<br>      return top<br>    }<br>  <br>    isEmpty() {<br>      // Return true if the stack is empty, false otherwise.<br>      return stack.length === 0<br>    }<br>  }</pre><p><strong>Congratulations</strong>! Now your are able to reproduce one of the most common used data structures with your favorite programming language.</p><p>In upcoming posts I will cover the “Queue” and “Linked list” implementations to continue with the data structure learning.</p><p>If you’d like to see the online implementation, I have posted the entire code on <a href="https://codepen.io/caparra92/pen/dyaYKWM">codePen</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea725cf2437c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some tools to practice your web dev skills]]></title>
            <link>https://medium.com/@caparra92/some-ways-to-practice-your-web-dev-skills-d9b8a86ecf57?source=rss-91540546be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9b8a86ecf57</guid>
            <category><![CDATA[frontend-mentor]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[css-challenges]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[hackerrank]]></category>
            <dc:creator><![CDATA[Camilo Andres Parra]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 02:17:04 GMT</pubDate>
            <atom:updated>2023-10-20T22:08:59.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="HTML code" src="https://cdn-images-1.medium.com/max/1024/1*C0io8c0jvhS3ci4qBClTaw.jpeg" /></figure><p>As far as I know, we are always trying to find a way to become better at something, but sometimes we do not know how to start or how to find good resources in order to become more familiar with this specific skill. If you are a web developer like me (it does not matter if you are new to web development or have a few years of experience; this article is also for you), you may find that the only way to practice programming or frontend skills is by doing or creating. I love reading. You can learn a lot of things from books or articles (such as this one), but the most crucial aspect of coding is consistent practice to develop the muscle memory needed for effective coding.</p><p>So now, I’ve compliled a list of resources that I believe will assist you on your learning journey.</p><ol><li><strong>Frontend mentor</strong></li></ol><p>This website allows you to learn HTML, CSS, and JavaScript concepts by solving challenges, and after you finish, you can post them so the community can see your work.</p><p>Avalilable at</p><p><a href="https://www.frontendmentor.io/">Frontend Mentor | Front-end coding challenges using a real-life workflow</a></p><p><strong>2. HackerRank</strong></p><p>This platform, even used by companies to create technical interviews for developer positions, is one of the most useful websites for training logic and solving a large variety of problems, including data structures, design patterns, and algorithms in languages such as JavaScript, Java, or Python.</p><p>Available at</p><p><a href="https://www.hackerrank.com/">HackerRank - Online Coding Tests and Technical Interviews</a></p><p><strong>3. CSS challenges</strong></p><p>As the website says, “Unleash your CSS skills,” it was created with the purpose of improving frontend skills by resolving challenges at different levels (easy, medium, and hard). If you are new to web development, I advise you to start with easy challenges so you can spend less time coding and thinking about the solution, and, after this, you can go to the next problem and measure your progress over time.</p><p>Available at</p><p><a href="https://css-challenges.com/">CSS Challenges - Become a Better Web Developer</a></p><p><strong>4. Chat GPT</strong></p><p>I cannot discuss training our development skills without mentioning AI tools. Given their increasing importancein the journey of developers, we need to take advantage of the large amount of information they provide. I’m saving generative AI for the end of this post because it requires well-crafted prompts to generate accurate solutions, so, for training purposes, we can try asking something like:</p><p>“Please provide beginner-level exercises on data structures in JavaScript” or “What are the most beginner-friendly Java design patterns to start with?”</p><p>You might be pleasantly surprised by the answers, so give it a try!</p><p>Available at</p><p><a href="https://chat.openai.com/">https://chat.openai.com/</a></p><p>That’s all for today. Happy coding and do not give up, you’ve got this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9b8a86ecf57" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>