<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Burhanuddin Mulla Hamzabhai</title>
        <link>https://burhanuddinhamzabhai.dev</link>
        <description>Articles written by burhanuddin mulla hamzabhai</description>
        <lastBuildDate>Sat, 07 Mar 2026 18:59:44 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>Burhanuddin Mulla Hamzabhai</title>
            <url>https://burhanuddinhamzabhai.dev/favicon.ico</url>
            <link>https://burhanuddinhamzabhai.dev</link>
        </image>
        <copyright>All rights reserved 2026</copyright>
        <item>
            <title><![CDATA[10 Indications the Developer Inside You is Dying]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/10-indications-the-developer-inside-you-is-dying</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/10-indications-the-developer-inside-you-is-dying</guid>
            <pubDate>Thu, 27 Jun 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>In the fast-paced world of software development, it’s easy to get caught up in deadlines, bugs, and endless lines of code. However, beneath the surface, the passion that once drove you to create innovative solutions can start to wane. Here are ten signs that the developer inside you might be dying and how to reignite that spark.</p>
<img alt="A tired female developer sitting at a desk with a laptop and coffee cup, holding her head in her hands." loading="lazy" width="1366" height="900" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2F10-indications-the-developer-inside-you-is-dying.020ee865.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2F10-indications-the-developer-inside-you-is-dying.020ee865.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2F10-indications-the-developer-inside-you-is-dying.020ee865.png&amp;w=3840&amp;q=75">
<h2>1. Lack of Curiosity</h2>
<p>Remember the days when you eagerly awaited new tech trends and updates? If you find yourself indifferent to the latest frameworks or languages, it might be a sign. Curiosity is a developer’s lifeblood; without it, your growth stagnates.</p>
<h2>2. Dreading Work</h2>
<p>Everyone has off days, but if the thought of sitting down to code fills you with dread more often than not, it’s a red flag. Passion should drive your work, not just a paycheck.</p>
<h2>3. Sticking to Old Tools</h2>
<p>Using what you know is comfortable, but if you’re resistant to learning new tools or technologies, you might be stifling your development. Innovation requires adaptation.</p>
<h2>4. Avoiding Collaboration</h2>
<p>Great software development is often a team effort. If you’re isolating yourself and avoiding collaboration, you might be missing out on valuable insights and learning opportunities.</p>
<h2>5. Neglecting Best Practices</h2>
<p>Are you cutting corners and ignoring best practices like code reviews and documentation? These shortcuts can lead to bigger problems down the line and indicate a loss of pride in your work.</p>
<h2>6. Burnout Symptoms</h2>
<p>Persistent fatigue, lack of motivation, and feeling overwhelmed are all symptoms of burnout. It’s crucial to address these feelings before they lead to more serious health issues.</p>
<h2>7. No Side Projects</h2>
<p>Side projects are a great way to experiment and learn without the pressure of deadlines. If you haven’t felt the urge to start something new for fun, it might be time to reassess your engagement with the craft.</p>
<h2>8. Stagnant Skillset</h2>
<p>The tech industry evolves rapidly. If you’re not learning and growing, your skills can quickly become obsolete. Continuous learning is essential to stay relevant and excited about your work.</p>
<h2>9. Lack of Community Involvement</h2>
<p>Engaging with the developer community through forums, meetups, or conferences can reignite your passion. If you’re not involved, you might be missing out on inspiration and networking opportunities.</p>
<h2>10. Feeling Disconnected from Your Work</h2>
<p>If you feel disconnected from the purpose of your projects, it’s hard to stay motivated. Try to find meaning in your work, whether through the impact it has or the problems it solves.</p>
<h2>Reignite Your Passion</h2>
<p>Recognizing these signs is the first step to reigniting your passion. Take a break if you need to, explore new technologies, and reconnect with the developer community. Remember, it’s never too late to reignite the spark that made you fall in love with coding in the first place.</p>
<blockquote>
<p>“Let your code be not just a creation, but a reflection of your passion reborn with every keystroke.” — Burhanuddin Mulla Hamzabhai</p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Angular is an Enigma Wrapped in Code]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/angular-is-an-enigma-wrapped-in-code</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/angular-is-an-enigma-wrapped-in-code</guid>
            <pubDate>Sat, 06 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Unlocking the Mysteries of Angular: A Deep Dive into the Modern Front-end Framework</p>
<img alt="Exploring the Depths of Angular" loading="lazy" width="1622" height="897" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fangular-is-an-enigma-wrapped-in-code.56682c1b.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fangular-is-an-enigma-wrapped-in-code.56682c1b.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fangular-is-an-enigma-wrapped-in-code.56682c1b.png&amp;w=3840&amp;q=75">
<p>Angular is a robust and intricate front-end framework developed by Google. Despite its complexities, it offers unparalleled benefits for web development projects. For many developers, Angular might seem like an enigma — its architecture, concepts, and syntax can be challenging to grasp at first. However, once you unlock its secrets, you’ll find a powerful toolset capable of creating dynamic and responsive web applications.</p>
<h2>Understanding Angular’s Architecture</h2>
<p>Angular’s architecture is built around the concept of modules, components, services, and dependency injection. Each of these plays a crucial role in the development process.</p>
<h2>Modules</h2>
<p>Modules in Angular are containers for different parts of your application. They help in organizing the application into cohesive blocks of functionality.</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NgModule</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>
<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">BrowserModule</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/platform-browser'</span><span class="token punctuation">;</span>
<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">AppComponent</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'./app.component'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">NgModule</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  declarations<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token maybe-class-name">AppComponent</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  imports<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token maybe-class-name">BrowserModule</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  providers<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  bootstrap<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token maybe-class-name">AppComponent</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">AppModule</span></span> <span class="token punctuation">{</span> <span class="token punctuation">}</span>
</code></pre>
<h2>Components</h2>
<p>Components are the building blocks of an Angular application. They control a part of the user interface and communicate with other components and services.</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Component</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  selector<span class="token operator">:</span> <span class="token string">'app-root'</span><span class="token punctuation">,</span>
  template<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">&lt;h1&gt;Welcome to Angular!&lt;/h1&gt;</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
  styles<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'h1 { font-family: Lato; }'</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">AppComponent</span></span> <span class="token punctuation">{</span> <span class="token punctuation">}</span>
</code></pre>
<h2>Services and Dependency Injection</h2>
<p>Services in Angular are used to encapsulate business logic. They can be injected into components or other services using Angular’s dependency injection system.</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Injectable</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Injectable</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  providedIn<span class="token operator">:</span> <span class="token string">'root'</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">DataService</span></span> <span class="token punctuation">{</span>
  <span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">return</span> <span class="token punctuation">[</span><span class="token string">'Data 1'</span><span class="token punctuation">,</span> <span class="token string">'Data 2'</span><span class="token punctuation">,</span> <span class="token string">'Data 3'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>The New Standalone Feature</h2>
<p>Angular has introduced a new feature called “standalone components” to simplify the development process. Standalone components eliminate the need to declare components in an NgModule, making it easier to manage and develop components independently.</p>
<h2>Creating a Standalone Component</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Component</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>
<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> bootstrapApplication <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/platform-browser'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  selector<span class="token operator">:</span> <span class="token string">'app-standalone'</span><span class="token punctuation">,</span>
  template<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">&lt;h2&gt;Standalone Component&lt;/h2&gt;</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
  standalone<span class="token operator">:</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">StandaloneComponent</span></span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token function">bootstrapApplication</span><span class="token punctuation">(</span><span class="token maybe-class-name">StandaloneComponent</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>Standalone components can be bootstrapped directly without the need for an NgModule. This feature enhances modularity and reduces the boilerplate code, making Angular more accessible for developers.</p>
<h2>Why Angular?</h2>
<p>Angular stands out due to its comprehensive framework that includes everything needed for a large-scale application. This includes powerful tools like the Angular CLI for project scaffolding, Angular Router for navigation, and built-in support for RxJS for reactive programming.</p>
<h2>Angular CLI</h2>
<p>The Angular CLI simplifies the development process by automating repetitive tasks and ensuring best practices.</p>
<pre class="language-bash"><code class="language-bash">ng new my-angular-app
<span class="token builtin class-name">cd</span> my-angular-app
ng serve
</code></pre>
<h2>Reactive Programming with RxJS</h2>
<p>Angular’s integration with RxJS allows for reactive programming, making it easier to handle asynchronous data streams.</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Component</span><span class="token punctuation">,</span> <span class="token maybe-class-name">OnInit</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>
<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Observable</span><span class="token punctuation">,</span> <span class="token keyword">of</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'rxjs'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  selector<span class="token operator">:</span> <span class="token string">'app-data'</span><span class="token punctuation">,</span>
  template<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">&lt;div *ngFor="let item of data$ | async"&gt;{{ item }}&lt;/div&gt;</span><span class="token template-punctuation string">`</span></span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">DataComponent</span></span> <span class="token keyword">implements</span> <span class="token class-name"><span class="token maybe-class-name">OnInit</span></span> <span class="token punctuation">{</span>
  data$<span class="token operator">:</span> <span class="token maybe-class-name">Observable</span><span class="token operator">&lt;</span><span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span><span class="token punctuation">;</span>

  <span class="token function">ngOnInit</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">data$</span> <span class="token operator">=</span> <span class="token keyword">of</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'Item 1'</span><span class="token punctuation">,</span> <span class="token string">'Item 2'</span><span class="token punctuation">,</span> <span class="token string">'Item 3'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Conclusion</h2>
<p>Angular is indeed an enigma wrapped in code. Its steep learning curve might deter some, but those who invest the time to understand its intricacies will find it to be an invaluable tool in their development arsenal. With its comprehensive framework and powerful features, including the new standalone components, Angular is poised to remain a leading choice for frontend development.</p>
<blockquote>
<p>“Mastering Angular is not about conquering its complexity, but about understanding its harmony and leveraging it to build exceptional applications.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>
<p>By demystifying Angular’s complexities, you can unlock its full potential and harness its capabilities to create robust and dynamic web applications. Whether you’re a seasoned developer or just starting out, diving deep into Angular can be a rewarding journey.</p>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Mastering the Art of Writing Clean and Maintainable JavaScript Code]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/art-of-writing-clean-and-maintainable-javascript</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/art-of-writing-clean-and-maintainable-javascript</guid>
            <pubDate>Wed, 11 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Elevate Your JavaScript Skills by Embracing Clean Code Practices</p>
<img alt="Article on Art of Writing Clean and Maintainable JavaScript" loading="lazy" width="1597" height="890" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fart-of-writing-clean-and-maintainable-javascript.ad892130.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fart-of-writing-clean-and-maintainable-javascript.ad892130.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fart-of-writing-clean-and-maintainable-javascript.ad892130.png&amp;w=3840&amp;q=75">
<p>In today’s fast-paced development industry, creating clean and maintainable JavaScript is not a luxury, but a requirement. Whether you are a single developer or part of a large team, maintainable code facilitates communication, lowers defects, and ensures scalability. Mastering the skill of producing clean code is essential for true software development success.</p>
<h2>Why Clean Code Matters</h2>
<p>Clean code is more than simply aesthetically pleasing; it has a direct impact on the success and longevity of your project. Clean and maintainable JavaScript ensures the following:</p>
<p><strong>Ease of collaboration:</strong> Collaboration is made easier when the code is well-structured.
<strong>Lower bug counts:</strong> Readable code makes it easier to find and fix bugs.
<strong>Scalability:</strong> Modular and well-organized code may be quickly expanded as your project grows.
<strong>Improved performance:</strong> Clean code frequently leads to greater optimization, which means faster execution.</p>
<p>Let’s look at some essential ideas for building clean, maintainable JavaScript code.</p>
<ol>
<li>Use consistent naming conventions.</li>
</ol>
<p>Choosing sensible names for variables, functions, and classes is the cornerstone of clean code. Follow conventions like camelCase for variables and functions, and PascalCase for class names.</p>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">const</span> dt <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> x <span class="token operator">=</span> <span class="token function">calculateTotal</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">const</span> currentDate <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> totalAmount <span class="token operator">=</span> <span class="token function">calculateTotal</span><span class="token punctuation">(</span>price<span class="token punctuation">,</span> quantity<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<ol start="2">
<li>Write small and focused functions.</li>
</ol>
<p>Functions should ideally accomplish a single purpose. If your function performs many tasks, it becomes more difficult to test and maintain. Small, modular functions encourage code reuse and facilitate debugging.</p>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">function</span> <span class="token function">processOrder</span><span class="token punctuation">(</span><span class="token parameter">order</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">validateOrder</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">saveOrderToDatabase</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">sendEmailConfirmation</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">function</span> <span class="token function">processOrder</span><span class="token punctuation">(</span><span class="token parameter">order</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">validateOrder</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">saveOrder</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">sendConfirmationEmail</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">validateOrder</span><span class="token punctuation">(</span><span class="token parameter">order</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">/* ... */</span> <span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">saveOrder</span><span class="token punctuation">(</span><span class="token parameter">order</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">/* ... */</span> <span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">sendConfirmationEmail</span><span class="token punctuation">(</span><span class="token parameter">order</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">/* ... */</span> <span class="token punctuation">}</span>
</code></pre>
<ol start="3">
<li>Avoid deep nesting.
Deeply nested code can be difficult to follow and maintain. Break down complex logic into smaller functions to avoid excessive nesting.</li>
</ol>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>user<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token property-access">isAdmin</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token function">hasPermission</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// do something</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token function">isAdminUser</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token function">hasPermission</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// do something</span>
<span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">isAdminUser</span><span class="token punctuation">(</span><span class="token parameter">user</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">return</span> user <span class="token operator">&amp;&amp;</span> user<span class="token punctuation">.</span><span class="token property-access">isAdmin</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<ol start="4">
<li>Use ES6+ features. Wisely
JavaScript has developed over time, and new features might help you write cleaner, more concise code. Use arrow functions, destructuring, and template literals to their full potential.</li>
</ol>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">function</span> <span class="token function">greet</span><span class="token punctuation">(</span><span class="token parameter">name</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">return</span> <span class="token string">'Hello, '</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">'!'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">const</span> <span class="token function-variable function">greet</span> <span class="token operator">=</span> <span class="token parameter">name</span> <span class="token arrow operator">=&gt;</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Hello, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">!</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
</code></pre>
<ol start="5">
<li>Embrace DRY (Do Not Repeat Yourself).
Duplication of code indicates that your code may be more difficult to maintain. Always try to restructure repetitive functionality into reusable functions or components.</li>
</ol>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">const</span> userGreeting <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Hello, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>user<span class="token punctuation">.</span><span class="token property-access">name</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">!</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
<span class="token keyword">const</span> adminGreeting <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Hello, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>admin<span class="token punctuation">.</span><span class="token property-access">name</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">!</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">const</span> <span class="token function-variable function">greetUser</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">role<span class="token punctuation">,</span> name</span><span class="token punctuation">)</span> <span class="token arrow operator">=&gt;</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Hello, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>role<span class="token punctuation">.</span><span class="token property-access">name</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">!</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
</code></pre>
<ol start="6">
<li>Comment wisely.
Comments should not describe what the code does; clean code should be self-explanatory. Instead, use comments to clarify why specific decisions were made, especially if they are not evident.</li>
</ol>
<p>Bad example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token comment">// increment x</span>
x<span class="token operator">++</span><span class="token punctuation">;</span>
</code></pre>
<p>Good example:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token comment">// Using a global counter to track user sessions.</span>
sessionCounter<span class="token punctuation">.</span><span class="token method function property-access">increment</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<ol start="7">
<li>
<p>Create meaningful tests.
Unit tests serve an important part in guaranteeing code maintainability. They help you ensure that your code works as expected and make reworking safer. Jest and Mocha are great for testing JavaScript code.</p>
</li>
<li>
<p>Use Linting Tools.
JavaScript linting tools, such as ESLint, help maintain a uniform style throughout your codebase and identify possible flaws before they become problems. It’s a good idea to configure ESLint with rigorous rule sets for each project.</p>
</li>
<li>
<p>Break down large code bases.
In huge projects, it is critical to divide your code into smaller modules. JavaScript modules (ES6 imports and exports) can be used to divide concerns while keeping the codebase reasonable.</p>
</li>
<li>
<p>Refactor often.
Refactoring is the process of rearranging old code without modifying its functionality. Regular refactoring helps maintain your code clean and efficient. As you develop new features, don’t be afraid to revisit and improve existing code.</p>
</li>
</ol>
<h2>Conclusion</h2>
<p>Writing clean and maintainable JavaScript code is a continuous process, not a one-time effort. It demands discipline and attention to detail, but the benefits are enormous: a more efficient, scalable, and entertaining codebase. By adhering to these principles, you will not only write better JavaScript, but also create a healthier development environment for yourself and your team.</p>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[CSS Grid vs. Flexbox: Navigating the Perfect Layout Solution]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/css-grid-vs-flexbox</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/css-grid-vs-flexbox</guid>
            <pubDate>Wed, 28 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>A Comprehensive Guide to Understanding and Choosing Between CSS Grid and Flexbox for Modern Web Layouts</p>
<img alt="Article on CSS Grid vs Flexbox" loading="lazy" width="1287" height="907" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-grid-vs-flexbox.97a51c8b.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-grid-vs-flexbox.97a51c8b.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-grid-vs-flexbox.97a51c8b.png&amp;w=3840&amp;q=75">
<p>In the world of web design, layout is king. CSS Grid and Flexbox are two of the most powerful techniques that developers have at their disposal. Both provide reliable options for designing dynamic and responsive designs, but they serve different functions and thrive in different situations. Understanding when and how to use each can mean the difference between a good and excellent website.</p>
<h2>Understanding CSS Grid and Flexbox</h2>
<p>CSS Grid is a two-dimensional layout technique that supports both rows and columns. It’s similar to having a table, but much more flexible. CSS Grid enables you to easily design complicated layouts, aligning things horizontally and vertically without the need for additional markup.</p>
<p>Flexbox (sometimes called Flexible Box Layout) is a one-dimensional layout method. It is intended to lay out objects in either a row or a column, not both at the same time. Flexbox excels when it comes to distributing space between things in an interface and aligning items within a container, especially when the size of your components is unknown or changeable.</p>
<h2>Key Differences</h2>
<h2>Dimensionality:</h2>
<p>Grid: Operates in two dimensions, handling rows and columns simultaneously.
Flexbox: Operates in one dimension at a time, either as a row or a column.</p>
<h2>Use cases:</h2>
<p>Grid: Ideal for designing complete page layouts or intricate components that require control over both axes.
Flexbox: is ideal for simple layouts that require distributing space among elements along a single axis, such as navigation bars, toolbars, or media object alignment.</p>
<h2>Complexity:</h2>
<p>Grid: Provides greater control and is ideal for larger-scale designs. However, it can be more difficult to learn and apply.
Flexbox: is easier to learn and use, making it ideal for smaller, less complex layouts.</p>
<h2>Alignment:</h2>
<p>Grid: Aligns information using grid lines, enabling more sophisticated and exact alignment.
Flexbox: Aligns things along the flex container’s main and cross axes, making it easier but less powerful than Grid.</p>
<h2>When to Use CSS Grid</h2>
<p>Full-page layouts: When constructing a full-page layout with several sections that must be aligned in both directions, use Grid. It divides the page into rows and columns, giving you complete control over where things appear.</p>
<p>Complex designs: Grid gives the resources needed to develop sophisticated layouts for interfaces that demand a more elaborate structure, such as dashboards or multimedia pages, without the use of hacks or complex nesting.</p>
<p>Grid’s ability to rearrange things across both axes makes it perfect for designing layouts that must adapt to various screen sizes and orientations.</p>
<h2>When to Use Flexbox</h2>
<p>Flexbox excels in basic instances when you just need to lay out things in one direction, either horizontally or vertically. Think of navigation bars, button groups, and card layouts.</p>
<p>If your content size is dynamic (for example, photos with different dimensions or text that varies based on user input), Flexbox can help guarantee that objects resize and align properly.</p>
<p>Alignment and space distribution: Flexbox excels in distributing space within a container and aligning items along a single axis, making it the preferred choice for many UI elements.</p>
<h2>Combining Grid and Flexbox</h2>
<p>In many circumstances, the optimum strategy is to use both Grid and Flexbox. For example, you could use Grid to arrange the entire page layout and Flexbox to fine-tune the layout of specific components. This method allows you to combine the strengths of both systems, resulting in a design that is both powerful and adaptable.</p>
<h2>Conclusion</h2>
<p>Your individual layout requirements will determine whether you use CSS Grid or Flexbox. If you require a strong, two-dimensional layout framework, CSS Grid is your best option. Flexbox is the best option for one-dimensional layouts since it is simpler and more versatile. Understanding each tool’s strengths and limits can allow you to create more efficient, responsive, and visually appealing web designs.</p>
<blockquote>
<p>“In web design, the tools you choose shape the experience you create.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[CSS is an Incredibly Beautiful Song]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/css-is-an-incredibly-beautiful-song</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/css-is-an-incredibly-beautiful-song</guid>
            <pubDate>Wed, 03 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Discover the Artistry and Elegance Behind Cascading Style Sheets</p>
<img alt="The Symphony of CSS in Web Design" loading="lazy" width="1362" height="905" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-is-an-incredibly-beautiful-song.ff81ca81.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-is-an-incredibly-beautiful-song.ff81ca81.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fcss-is-an-incredibly-beautiful-song.ff81ca81.png&amp;w=3840&amp;q=75">
<p>In the world of web development, CSS (Cascading Style Sheets) is often likened to the notes of a song, meticulously arranged to create a harmonious and visually appealing experience. Much like a composer crafts a symphony, a web designer uses CSS to bring life and beauty to web pages. In this article, we’ll explore the artistry behind CSS and share some amazing things you can do with it.</p>
<h2>The Harmony of CSS</h2>
<p>CSS brings harmony to web design. Just as a song comprises various notes and rhythms, a well-crafted website blends colors, fonts, and layouts to create a cohesive and engaging experience. CSS is the conductor of this digital orchestra, ensuring every element is in perfect sync.</p>
<p>CSS is the language that describes the presentation of web pages. It controls the layout, colors, fonts, and overall aesthetics. Without CSS, web pages would be a cacophony of unstyled HTML, lacking visual appeal. Here’s a simple example of how CSS can transform a basic HTML page:</p>
<p><strong><a href="https://codepen.io/burhanuddinmullahamzabhai/pen/WNBqJmz">Code Example:</a></strong></p>
<pre class="language-html"><code class="language-html"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
        <span class="token selector">body</span> <span class="token punctuation">{</span>
            <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token hexcode color">#f0f8ff</span><span class="token punctuation">;</span>
            <span class="token property">font-family</span><span class="token punctuation">:</span> Arial<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span>
            <span class="token property">color</span><span class="token punctuation">:</span> <span class="token hexcode color">#333</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token selector">h1</span> <span class="token punctuation">{</span>
            <span class="token property">color</span><span class="token punctuation">:</span> <span class="token hexcode color">#4682b4</span><span class="token punctuation">;</span>
            <span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
            <span class="token property">margin-top</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token unit">px</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token selector">p</span> <span class="token punctuation">{</span>
            <span class="token property">max-width</span><span class="token punctuation">:</span> <span class="token number">600</span><span class="token unit">px</span><span class="token punctuation">;</span>
            <span class="token property">margin</span><span class="token punctuation">:</span> <span class="token number">20</span><span class="token unit">px</span> auto<span class="token punctuation">;</span>
            <span class="token property">line-height</span><span class="token punctuation">:</span> <span class="token number">1.6</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">&gt;</span></span>Welcome to the Symphony of CSS<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>CSS transforms the web into a visually engaging platform, turning simple HTML into a beautifully orchestrated presentation. Let's explore some examples of CSS in action.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<h2>The Melody of Colors</h2>
<p>Colors in CSS are like the notes in a melody. They evoke emotions, set the tone, and guide the user’s journey through the website. By using a harmonious color palette, you can create a visually appealing and user-friendly interface. Tools like Adobe Color can help you choose complementary colors that enhance the overall aesthetic.</p>
<h2>The Rhythm of Layouts</h2>
<p>Layouts are the rhythm section of your website. CSS Grid and Flexbox allow you to create complex, responsive designs that adapt to various screen sizes. A well-structured layout ensures that content flows naturally and keeps users engaged. Resources like CSS-Tricks provide valuable insights and tutorials on mastering these techniques.</p>
<p>Flexbox and Grid are powerful layout systems in CSS that allow for responsive and complex designs with minimal effort. They are like the rhythm section of a band, providing structure and consistency.</p>
<p><strong><a href="https://codepen.io/burhanuddinmullahamzabhai/pen/OJYeZex">Flexbox Example:</a></strong></p>
<pre class="language-html"><code class="language-html"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
        <span class="token selector"><span class="token class">.container</span></span> <span class="token punctuation">{</span>
            <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
            <span class="token property">justify-content</span><span class="token punctuation">:</span> space-around<span class="token punctuation">;</span>
            <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
            <span class="token property">height</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token unit">vh</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token selector"><span class="token class">.box</span></span> <span class="token punctuation">{</span>
            <span class="token property">width</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token unit">px</span><span class="token punctuation">;</span>
            <span class="token property">height</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token unit">px</span><span class="token punctuation">;</span>
            <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token hexcode color">#87ceeb</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>container<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p><strong><a href="https://codepen.io/burhanuddinmullahamzabhai/pen/LYoKmwG">Grid Example:</a></strong></p>
<pre class="language-html"><code class="language-html"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
        <span class="token selector"><span class="token class">.grid-container</span></span> <span class="token punctuation">{</span>
            <span class="token property">display</span><span class="token punctuation">:</span> grid<span class="token punctuation">;</span>
            <span class="token property">grid-template-columns</span><span class="token punctuation">:</span> <span class="token function">repeat</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token unit">fr</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token property">gap</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token unit">px</span><span class="token punctuation">;</span>
            <span class="token property">padding</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token unit">px</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token selector"><span class="token class">.grid-item</span></span> <span class="token punctuation">{</span>
            <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token hexcode color">#87ceeb</span><span class="token punctuation">;</span>
            <span class="token property">padding</span><span class="token punctuation">:</span> <span class="token number">20</span><span class="token unit">px</span><span class="token punctuation">;</span>
            <span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-container<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>5<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>grid-item<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<h2>The Lyrics of Typography</h2>
<p>Typography is the lyrical component of your website. The choice of fonts and their styling can significantly impact readability and user experience. CSS allows you to experiment with various font families, sizes, and weights to find the perfect combination. Google Fonts offers a vast collection of web-safe fonts to enhance your site’s typography.</p>
<h2>Creating Visual Symphonies</h2>
<p>CSS is not just about making things look pretty; it’s about creating visual symphonies that enhance usability and accessibility. Techniques like animations and transitions can add subtle interactions that delight users without overwhelming them. Libraries like Animate.css make it easy to implement these effects.</p>
<p>Animations can add a dynamic layer to your design, capturing attention and enhancing user experience. CSS animations are easy to implement and can make your website feel more interactive.</p>
<p><strong><a href="https://codepen.io/burhanuddinmullahamzabhai/pen/xxNozKb">Code Example:</a></strong></p>
<pre class="language-html"><code class="language-html"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
        <span class="token atrule"><span class="token rule">@keyframes</span> fadeIn</span> <span class="token punctuation">{</span>
            <span class="token selector">from</span> <span class="token punctuation">{</span> <span class="token property">opacity</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
            <span class="token selector">to</span> <span class="token punctuation">{</span> <span class="token property">opacity</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token selector"><span class="token class">.fade-in</span></span> <span class="token punctuation">{</span>
            <span class="token property">animation</span><span class="token punctuation">:</span> fadeIn <span class="token number">2</span><span class="token unit">s</span> ease-in<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fade-in<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>CSS Animations<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fade-in<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Animations add life to your web pages, making them more engaging and interactive.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<h2>Accessibility Matters</h2>
<p>Ensuring your website is accessible to everyone is crucial. CSS plays a vital role in making web content accessible to users with disabilities. By using semantic HTML and CSS, you can improve navigation and readability for screen readers. The Web Content Accessibility Guidelines (WCAG) provide a comprehensive framework for achieving this.</p>
<h2>Conclusion</h2>
<p>CSS is not just a tool; it’s an art form. It transforms plain HTML into beautiful, responsive, and interactive web pages. By mastering CSS, you can create web designs that are not only functional but also aesthetically pleasing, much like a beautiful song that resonates with its audience.</p>
<p>CSS is indeed an incredibly beautiful song, one that web developers have the privilege of composing. By mastering the nuances of CSS, you can create websites that are not only visually appealing but also functional and accessible. So, let your creativity flow, and let CSS be the melody that brings your web designs to life.</p>
<blockquote>
<p>“CSS is the brush, HTML is the canvas, and your creativity is the masterpiece.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Javascript is a sea and you are in a life jacket]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/javascript-is-a-sea-and-you-are-in-a-life-jacket</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/javascript-is-a-sea-and-you-are-in-a-life-jacket</guid>
            <pubDate>Sun, 30 Jun 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Navigating the Vast and Ever-Evolving World of JavaScript</p>
<img alt="Person struggling to stay afloat in the ocean, symbolizing the challenges of mastering JavaScript." loading="lazy" width="1593" height="887" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fjavascript-is-a-sea-and-you-are-in-a-life-jacket.a6970ebe.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fjavascript-is-a-sea-and-you-are-in-a-life-jacket.a6970ebe.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fjavascript-is-a-sea-and-you-are-in-a-life-jacket.a6970ebe.png&amp;w=3840&amp;q=75">
<h2>Introduction</h2>
<p>JavaScript is a sea, and you are in a life jacket. The analogy might sound dramatic, but if you’ve ever dived into JavaScript development, you know it fits. From its humble beginnings to becoming one of the most powerful and versatile programming languages in the world, JavaScript has grown into an ocean of frameworks, libraries, and tools. Whether you’re a beginner or an experienced developer, it’s crucial to know how to navigate these waters without feeling overwhelmed.</p>
<h2>Understanding the Basics</h2>
<p>Before setting sail, you need to understand the fundamentals of JavaScript. The core language itself is relatively simple, but its ecosystem can be daunting. Focus on mastering the basics:</p>
<ul>
<li>
<p><strong>Variables and Data Types:</strong> Understand how to declare variables using var, let, and const, and get familiar with JavaScript's data types like strings, numbers, and objects.</p>
</li>
<li>
<p><strong>Functions and Scope:</strong> Learn how to define and invoke functions, and grasp the concept of scope and closures.</p>
</li>
<li>
<p><strong>DOM Manipulation:</strong> Get comfortable with selecting and modifying HTML elements using JavaScript.</p>
</li>
</ul>
<h2>The Framework Frenzy</h2>
<p>Once you’re comfortable with the basics, you might be tempted to dive into frameworks. React, Angular, Vue.js — the list goes on. Each framework has its own strengths and community, and choosing one can feel like picking a boat in a bustling harbor. Here are a few tips to help you decide:</p>
<ul>
<li>
<p><strong>Project Requirements:</strong> Consider what your project needs. React is great for highly interactive UIs, while Angular offers a comprehensive solution with built-in features.</p>
</li>
<li>
<p><strong>Learning Curve:</strong> Assess how steep the learning curve is. Vue.js, for instance, is known for its gentle learning curve and ease of integration.</p>
</li>
<li>
<p><strong>Community and Support:</strong> A large, active community means more resources, tutorials, and plugins to help you out.</p>
</li>
</ul>
<h2>Staying Afloat with Tools and Libraries</h2>
<p>JavaScript is rich with tools and libraries designed to make your life easier. However, knowing which ones to use is crucial. Here are some essentials:</p>
<ul>
<li>
<p><strong>Webpack and Babel:</strong> These tools help you bundle your JavaScript files and ensure compatibility across different browsers.</p>
</li>
<li>
<p><strong>ESLint and Prettier:</strong> Keep your code clean and consistent with these linters and formatters.</p>
</li>
<li>
<p><strong>Testing Libraries:</strong> Jest and Mocha are popular choices for testing your code to ensure it works as expected.</p>
</li>
</ul>
<h2>Continuous Learning and Adaptation</h2>
<p>JavaScript is a rapidly evolving sea. New frameworks, libraries, and best practices emerge frequently. To stay afloat, continuous learning is vital:</p>
<ul>
<li>
<p><strong>Follow Blogs and Tutorials:</strong> Sites like Medium, Dev.to, and CSS-Tricks offer valuable insights and tutorials.</p>
</li>
<li>
<p><strong>Participate in Communities:</strong> Engage with other developers on platforms like Stack Overflow, GitHub, and Reddit.</p>
</li>
<li>
<p><strong>Attend Conferences and Meetups:</strong> Events like JSConf and local meetups provide opportunities to learn from experts and network with peers.</p>
</li>
</ul>
<h2>Conclusion</h2>
<p>Navigating the vast sea of JavaScript can be challenging, but with the right mindset and tools, you can keep afloat and steer your career in the right direction. Remember, every expert was once a beginner, and continuous learning is your best life jacket.</p>
<blockquote>
<p>“In the vast ocean of JavaScript, let continuous learning be your life jacket, keeping you afloat and guiding you to new horizons.” — Burhanuddin Mulla Hamzabhai</p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Why Functional Programming Should Precede OOP in Your Learning Journey]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/mastering-functional-programming-before-object-oriented-programming-a-modern-developers-guide</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/mastering-functional-programming-before-object-oriented-programming-a-modern-developers-guide</guid>
            <pubDate>Wed, 07 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Unlocking the Power of Functional Programming for Better Software Development</p>
<img alt="Guide to Functional Programming" loading="lazy" width="1207" height="902" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-functional-programming-before-object-oriented-programming-a-modern-developers-guide.d307df30.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-functional-programming-before-object-oriented-programming-a-modern-developers-guide.d307df30.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-functional-programming-before-object-oriented-programming-a-modern-developers-guide.d307df30.png&amp;w=3840&amp;q=75">
<p>In the field of software development, functional programming, or FP, has been gaining popularity, and for good reason. It has many benefits that can greatly improve your coding abilities and program design methodology, including its emphasis on immutability, first-class functions, and declarative style. Here are several reasons why you should learn functional programming before you dive into object-oriented programming (OOP).</p>
<h2>Functional Programming Foundations</h2>
<p>Functional programming is a paradigm that stays away from mutable data and changing states, instead treating computation as the evaluation of mathematical functions. Code written using this method is more predictable and testable. Here are a few fundamental ideas of FP:</p>
<p><strong>Immutability:</strong> Data structures in FP are unchangeable. This implies that a data structure cannot be altered once it has been constructed. Rather, functions don’t have side effects because new data structures are made as needed.</p>
<p><strong>First-Class Functions:</strong> Functions in FP are first-class citizens, which means they can be assigned to variables, supplied as arguments, and returned by other functions. Higher-order functions and more expressive code are made possible by this.</p>
<p><strong>Pure Functions:</strong> Pure functions don’t have any side effects and always return the same result for the same input. They are therefore simpler to test and reason about.</p>
<p><strong>Declarative Style:</strong> FP produces code that is easier to read and comprehend by emphasizing what has to be done rather than how to do it.</p>
<h2>Benefits of Learning Functional Programming First</h2>
<p><strong>Improved Code Quality:</strong> Writing clear, modular, and reusable code is encouraged by functional programming. Immutability and pure functions are key components that can help you minimize problems and improve the maintainability of your program.</p>
<p><strong>Easier to Learn Other Paradigms:</strong> Learning other paradigms, such as OOP, is made simpler if you have a solid understanding of functional programming. Programming styles can be applied on the robust base that the FP discipline offers.</p>
<p><strong>Improved comprehension of concurrency:</strong> Safer and more effective concurrent programming is a natural consequence of FP’s immutability and pure functions. In the world of multi-core processing today, being able to develop better concurrent code requires an understanding of these ideas.</p>
<p><strong>Improved Problem-Solving Ability:</strong> FP calls for a distinct way of thinking, which frequently results in more creative solutions. Learning FP first helps you cultivate a problem-solving approach that is very helpful when taking on challenging software problems.</p>
<h2>Practical Applications and Examples</h2>
<p>Let’s take a look at some practical examples to illustrate the power of functional programming.</p>
<p><strong>Example 1: Immutability</strong></p>
<pre class="language-javascript"><code class="language-javascript"><span class="token comment">// Mutable object example (OOP)</span>
<span class="token keyword">let</span> person <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'Alice'</span><span class="token punctuation">,</span> <span class="token literal-property property">age</span><span class="token operator">:</span> <span class="token number">25</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
person<span class="token punctuation">.</span><span class="token property-access">age</span> <span class="token operator">=</span> <span class="token number">26</span><span class="token punctuation">;</span> <span class="token comment">// Modifying the object</span>

<span class="token comment">// Immutable object example (FP)</span>
<span class="token keyword">const</span> person <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'Alice'</span><span class="token punctuation">,</span> <span class="token literal-property property">age</span><span class="token operator">:</span> <span class="token number">25</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> updatedPerson <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token spread operator">...</span>person<span class="token punctuation">,</span> <span class="token literal-property property">age</span><span class="token operator">:</span> <span class="token number">26</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">// Creating a new object</span>
</code></pre>
<p><strong>Example 2: Higher-Order Functions</strong></p>
<pre class="language-javascript"><code class="language-javascript"><span class="token comment">// Higher-order function example (FP)</span>
<span class="token keyword">const</span> numbers <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> doubled <span class="token operator">=</span> numbers<span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token parameter">num</span> <span class="token arrow operator">=&gt;</span> num <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Function passed as an argument</span>

<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>doubled<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Output: [2, 4, 6, 8, 10]</span>
</code></pre>
<h2>Combining OOP with FP</h2>
<p>You can combine the concepts of functional programming with object-oriented programming to create more reliable software designs once you’ve mastered it. You can take advantage of the advantages of both paradigms by using the support provided by several contemporary languages, such as Python, Scala, and JavaScript.</p>
<h2>In summary</h2>
<p>Gaining proficiency in functional programming prior to object-oriented programming will help you become a more efficient and adaptable developer. You can produce cleaner, more maintainable code and be more prepared to take on the problems of contemporary software development by comprehending and putting the ideas of FP to use.</p>
<blockquote>
<p>“Embrace the purity of functional programming, and you’ll find clarity in the chaos of code.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>
<p>Making functional programming a priority in your learning process can help you acquire important insights that will improve the way you approach software development and, in the end, improve your programming skills.</p>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[NoSQL Design Patterns: Best Practices for Schema-less Databases]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/mastering-nosql-design-patterns-best-practices-for-schema-less-databases</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/mastering-nosql-design-patterns-best-practices-for-schema-less-databases</guid>
            <pubDate>Wed, 02 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-chronicles/mastering-nosql-design-patterns-best-practices-for-schema-less-databases-2e2fc6f4ace6?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*7VR5WowMWSNbbGIfAo8w5g.png" alt=""></a></p>
<p>Unlock the full potential of NoSQL databases by leveraging proven design patterns for flexible, efficient, and scalable data models.</p>
<p>In recent years, NoSQL databases have emerged as a key component of modern application development. Their schema-less nature allows for greater flexibility and scalability than traditional relational databases. However, designing for a schema-less database brings unique issues, and failing to follow best practices might result in a disorganized, inefficient system. This is where noSQL design patterns come into play.</p>
<h2>What Are the NoSQL Design Patterns?</h2>
<p>NoSQL design patterns are predefined answers to common design issues in NoSQL systems. These patterns describe how to structure, store, and query data in a way that maximizes the database's strengths (scalability, flexibility, and availability) while reducing its limitations.</p>
<p>Below, we'll look at essential design principles and best practices for creating more efficient and scalable NoSQL systems.</p>
<h2>1. The Aggregation Pattern.</h2>
<p>Aggregation is a basic feature in NoSQL databases such as MongoDB, Cassandra, and Couchbase. NoSQL databases frequently store data as aggregates, which are collections of related objects, rather than normalized tables, as SQL databases do.</p>
<h2>Best Practice</h2>
<p>Organize data by business entities (e.g., user profiles, orders) rather than smaller bits. Keeping similar data together in a single document or record reduces the need for complex joins and improves speed, particularly in read-heavy applications.</p>
<h2>Example:</h2>
<p>In MongoDB, users and addresses can be stored in the same document rather than distinct collections.</p>
<pre class="language-json"><code class="language-json"><span class="token punctuation">{</span>
   <span class="token property">"_id"</span><span class="token operator">:</span> <span class="token string">"user_123"</span><span class="token punctuation">,</span>
   <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"John Doe"</span><span class="token punctuation">,</span>
   <span class="token property">"email"</span><span class="token operator">:</span> <span class="token string">"johndoe@gmail.com"</span><span class="token punctuation">,</span>
   <span class="token property">"addresses"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
         <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"home"</span><span class="token punctuation">,</span>
         <span class="token property">"address"</span><span class="token operator">:</span> <span class="token string">"123 Main St, City, Country"</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
         <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"work"</span><span class="token punctuation">,</span>
         <span class="token property">"address"</span><span class="token operator">:</span> <span class="token string">"456 Corporate Ave, City, Country"</span>
      <span class="token punctuation">}</span>
   <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>2. The Key-Value Pattern.</h2>
<p>Key-value stores, such as Redis and DynamoDB, excel at managing basic, fast-access data models. This pattern associates each item of data with a unique key, making it extremely efficient for lookups.</p>
<h2>Best Practice</h2>
<p>Use key-value design for fast lookups and low latency access. This technique is effective for caching, session management, and rapid retrieval of tiny datasets.</p>
<h2>Example</h2>
<p>A Redis record for storing user preferences could look like this:</p>
<pre class="language-bash"><code class="language-bash">SET user:123:theme dark
SET user:123:language en
</code></pre>
<p>Here, the user:123 is the key, and the theme and language are values associated with the key.</p>
<h2>3. The Document Storage Pattern.</h2>
<p>This approach serves as the foundation for document databases such as MongoDB. A document store organizes data into self-describing JSON, BSON, or XML documents. These documents can contain nested data, arrays, and fields, making them extremely versatile.</p>
<h2>Best Practice</h2>
<p>Use document repositories for unstructured or semi-structured data. This architecture is appropriate for applications that involve extensive data relationships but do not require a fixed schema, such as content management systems or product catalogs.</p>
<h2>Example</h2>
<p>Consider an e-commerce product catalog stored in MongoDB:</p>
<pre class="language-json"><code class="language-json"><span class="token punctuation">{</span>
   <span class="token property">"productId"</span><span class="token operator">:</span> <span class="token string">"prod_456"</span><span class="token punctuation">,</span>
   <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Smartphone"</span><span class="token punctuation">,</span>
   <span class="token property">"price"</span><span class="token operator">:</span> <span class="token number">699</span><span class="token punctuation">,</span>
   <span class="token property">"features"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">"storage"</span><span class="token operator">:</span> <span class="token string">"128GB"</span><span class="token punctuation">,</span>
      <span class="token property">"camera"</span><span class="token operator">:</span> <span class="token string">"12MP"</span><span class="token punctuation">,</span>
      <span class="token property">"battery"</span><span class="token operator">:</span> <span class="token string">"4000mAh"</span>
   <span class="token punctuation">}</span><span class="token punctuation">,</span>
   <span class="token property">"reviews"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
         <span class="token property">"username"</span><span class="token operator">:</span> <span class="token string">"tech_guru"</span><span class="token punctuation">,</span>
         <span class="token property">"rating"</span><span class="token operator">:</span> <span class="token number">5</span><span class="token punctuation">,</span>
         <span class="token property">"comment"</span><span class="token operator">:</span> <span class="token string">"Great value for the price!"</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
         <span class="token property">"username"</span><span class="token operator">:</span> <span class="token string">"shopaholic"</span><span class="token punctuation">,</span>
         <span class="token property">"rating"</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
         <span class="token property">"comment"</span><span class="token operator">:</span> <span class="token string">"Could improve battery life."</span>
      <span class="token punctuation">}</span>
   <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>4. The Wide Column Pattern.</h2>
<p>Wide column stores, such as Cassandra, are designed for scenarios that require large volumes of data over multiple columns. This pattern is ideal for systems with a flexible schema and sparsely populated column values.</p>
<h2>Best Practice</h2>
<p>This pattern is ideal for time-series data, logs, or IoT applications that require scalability and performance across distributed nodes.</p>
<h2>Example</h2>
<p>A Cassandra database for time-series weather data could look like this:</p>
<pre class="language-sql"><code class="language-sql"><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> weather_data <span class="token punctuation">(</span>
   station_id <span class="token keyword">TEXT</span><span class="token punctuation">,</span>
   <span class="token keyword">timestamp</span> <span class="token keyword">TIMESTAMP</span><span class="token punctuation">,</span>
   temperature <span class="token keyword">FLOAT</span><span class="token punctuation">,</span>
   humidity <span class="token keyword">FLOAT</span><span class="token punctuation">,</span>
   <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>station_id<span class="token punctuation">,</span> <span class="token keyword">timestamp</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>Here, data for different stations can vary in terms of which columns are populated, making it flexible while retaining performance.</p>
<h2>5. The Denormalization Pattern.</h2>
<p>Denormalization is the process of duplicating data across numerous records to increase read efficiency. While relational databases prefer normalizing to decrease redundancy, NoSQL databases benefit from denormalization to avoid costly joins between distributed systems.</p>
<h2>Best Practice</h2>
<p>Denormalizing data can enhance read efficiency in instances where it is regularly read but rarely modified. However, be cautious because duplication might make updates more complex and slow.</p>
<h2>Example</h2>
<p>For instance, instead of separating orders and products, consider denormalizing product data within the order document:</p>
<pre class="language-json"><code class="language-json"><span class="token punctuation">{</span>
   <span class="token property">"orderId"</span><span class="token operator">:</span> <span class="token string">"order_789"</span><span class="token punctuation">,</span>
   <span class="token property">"customerId"</span><span class="token operator">:</span> <span class="token string">"user_123"</span><span class="token punctuation">,</span>
   <span class="token property">"orderDate"</span><span class="token operator">:</span> <span class="token string">"2023-09-27"</span><span class="token punctuation">,</span>
   <span class="token property">"items"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span>
         <span class="token property">"productId"</span><span class="token operator">:</span> <span class="token string">"prod_456"</span><span class="token punctuation">,</span>
         <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Smartphone"</span><span class="token punctuation">,</span>
         <span class="token property">"price"</span><span class="token operator">:</span> <span class="token number">699</span><span class="token punctuation">,</span>
         <span class="token property">"quantity"</span><span class="token operator">:</span> <span class="token number">1</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
         <span class="token property">"productId"</span><span class="token operator">:</span> <span class="token string">"prod_789"</span><span class="token punctuation">,</span>
         <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Headphones"</span><span class="token punctuation">,</span>
         <span class="token property">"price"</span><span class="token operator">:</span> <span class="token number">199</span><span class="token punctuation">,</span>
         <span class="token property">"quantity"</span><span class="token operator">:</span> <span class="token number">1</span>
      <span class="token punctuation">}</span>
   <span class="token punctuation">]</span><span class="token punctuation">,</span>
   <span class="token property">"total"</span><span class="token operator">:</span> <span class="token number">898</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>6. The Event Sourcing Pattern.</h2>
<p>Event sourcing can be an effective pattern in systems that require tracking of changes over time (for example, auditing or financial systems). You store a sequence of state-changing events rather than just the object’s present state.</p>
<h2>Best practice</h2>
<p>Use event sourcing to recover an entity’s complete history. This pattern is valuable in fields like as banking, insurance, and real-time analytics.</p>
<h2>Example</h2>
<p>An event log for a bank account transaction:</p>
<pre class="language-json"><code class="language-JSON"><span class="token punctuation">[</span>
   <span class="token punctuation">{</span>
      <span class="token property">"transactionId"</span><span class="token operator">:</span> <span class="token string">"tx_001"</span><span class="token punctuation">,</span>
      <span class="token property">"accountId"</span><span class="token operator">:</span> <span class="token string">"acc_123"</span><span class="token punctuation">,</span>
      <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"deposit"</span><span class="token punctuation">,</span>
      <span class="token property">"amount"</span><span class="token operator">:</span> <span class="token number">100</span><span class="token punctuation">,</span>
      <span class="token property">"timestamp"</span><span class="token operator">:</span> <span class="token string">"2024-01-01T10:00:00Z"</span>
   <span class="token punctuation">}</span><span class="token punctuation">,</span>
   <span class="token punctuation">{</span>
      <span class="token property">"transactionId"</span><span class="token operator">:</span> <span class="token string">"tx_002"</span><span class="token punctuation">,</span>
      <span class="token property">"accountId"</span><span class="token operator">:</span> <span class="token string">"acc_123"</span><span class="token punctuation">,</span>
      <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"withdrawal"</span><span class="token punctuation">,</span>
      <span class="token property">"amount"</span><span class="token operator">:</span> <span class="token number">50</span><span class="token punctuation">,</span>
      <span class="token property">"timestamp"</span><span class="token operator">:</span> <span class="token string">"2024-01-02T12:00:00Z"</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre>
<h2>Final Thoughts</h2>
<p>NoSQL databases offer unparalleled flexibility, but with great power comes great responsibility. By using these proven NoSQL design patterns, you can build systems that scale efficiently and handle the flexibility that schema-less databases provide. The right pattern can improve not only performance but also maintainability and scalability over time.</p>
<blockquote>
<p>“In the world of NoSQL, understanding design patterns is the key to unlocking true scalability and efficiency.” — Burhanuddin Mulla Hamzabhai</p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[React is Good, but Angular Takes My Heart]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/react-is-good-but-angular-takes-my-heart</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/react-is-good-but-angular-takes-my-heart</guid>
            <pubDate>Mon, 15 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Understanding the Key Differences That Make Angular Stand Out.</p>
<img alt="Angular’s structured framework offers a compelling edge over React" loading="lazy" width="1283" height="902" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Freact-is-good-but-angular-takes-my-heart.3e35eca3.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Freact-is-good-but-angular-takes-my-heart.3e35eca3.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Freact-is-good-but-angular-takes-my-heart.3e35eca3.png&amp;w=3840&amp;q=75">
<p>In the ever-evolving world of web development, two giants often come head-to-head: React and Angular. Both have their strengths, but after working extensively with both, I find myself leaning towards Angular. Here’s why Angular takes my heart, despite React’s undeniable capabilities.</p>
<h2>Structured Framework</h2>
<p>Angular’s robust framework provides a comprehensive solution right out of the box. Unlike React, which is more of a library that requires additional tools and libraries to manage state and routing, Angular offers a complete package. This includes tools for dependency injection, two-way data binding, and comprehensive routing.</p>
<h2>Example: Dependency Injection in Angular</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Injectable</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Injectable</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  providedIn<span class="token operator">:</span> <span class="token string">'root'</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">DataService</span></span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token punctuation">}</span>

  <span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">return</span> <span class="token punctuation">[</span><span class="token string">'Angular'</span><span class="token punctuation">,</span> <span class="token string">'React'</span><span class="token punctuation">,</span> <span class="token string">'Vue'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Dependency injection in Angular allows for a cleaner, more modular codebase. The @Injectable decorator ensures that the service can be injected into components, making it easy to manage dependencies and promote code reusability.</p>
<h2>TypeScript Integration</h2>
<p>TypeScript is a statically typed language that adds rigor to JavaScript code. Angular, being built with TypeScript, provides a seamless experience for developers who prefer static typing. This not only reduces bugs but also enhances code readability and maintainability.</p>
<h2>Example: TypeScript in Angular</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Component</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'@angular/core'</span><span class="token punctuation">;</span>

<span class="token decorator"><span class="token at operator">@</span><span class="token function">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  selector<span class="token operator">:</span> <span class="token string">'app-root'</span><span class="token punctuation">,</span>
  template<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">&lt;h1&gt;{{ title }}&lt;/h1&gt;</span><span class="token template-punctuation string">`</span></span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword module">export</span> <span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">AppComponent</span></span> <span class="token punctuation">{</span>
  title<span class="token operator">:</span> <span class="token builtin">string</span> <span class="token operator">=</span> <span class="token string">'Hello Angular!'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>TypeScript’s static typing and advanced features like interfaces and decorators align perfectly with Angular’s framework. This integration ensures that developers can catch errors early in the development process, leading to more robust applications.</p>
<h2>Two-Way Data Binding</h2>
<p>Angular’s two-way data binding is a game-changer, especially for complex applications. It ensures that the model and the view are always in sync, reducing the amount of boilerplate code and making the development process more efficient.</p>
<h2>Example: Two-Way Data Binding</h2>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">[(ngModel)]</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Enter your name<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>Hello, {{ name }}!<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>Two-way data binding simplifies the interaction between the user interface and the application logic. With Angular’s ngModel directive, developers can effortlessly bind input fields to model properties, ensuring real-time updates and a smoother user experience.</p>
<h2>Comprehensive CLI</h2>
<p>Angular’s CLI is another feature that enhances the development experience. It allows for quick scaffolding of new projects, generating components, services, and more with simple commands. This leads to a more organized and efficient development process.</p>
<h2>Example: Angular CLI Command</h2>
<pre class="language-bash"><code class="language-bash">ng generate component my-new-component
</code></pre>
<p>The Angular CLI streamlines the development workflow, reducing setup time and minimizing errors. By automating repetitive tasks, the CLI allows developers to focus on writing code and implementing features, ultimately speeding up the development cycle.</p>
<h2>React’s Flexibility vs. Angular’s Structure</h2>
<p>React offers unparalleled flexibility, allowing developers to pick and choose the libraries and tools that best fit their project needs. This modular approach can be liberating, but it also requires more decision-making and setup time. Angular, on the other hand, provides a well-defined structure that streamlines the development process, which can be a huge advantage for larger projects or teams.</p>
<h2>Example: React with State Management</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword module">import</span> <span class="token imports"><span class="token maybe-class-name">React</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> useState <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">'react'</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>name<span class="token punctuation">,</span> setName<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>
    <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span>input 
        type<span class="token operator">=</span><span class="token string">"text"</span> 
        value<span class="token operator">=</span><span class="token punctuation">{</span>name<span class="token punctuation">}</span> 
        onChange<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span> <span class="token arrow operator">=&gt;</span> <span class="token function">setName</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">)</span><span class="token punctuation">}</span> 
        placeholder<span class="token operator">=</span><span class="token string">"Enter your name"</span>
      <span class="token operator">/</span><span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span>p<span class="token operator">&gt;</span><span class="token maybe-class-name">Hello</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>name<span class="token punctuation">}</span><span class="token operator">!</span><span class="token operator">&lt;</span><span class="token operator">/</span>p<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword module">export</span> <span class="token keyword module">default</span> <span class="token maybe-class-name">App</span><span class="token punctuation">;</span>
</code></pre>
<p>While React’s flexibility allows for tailored solutions, it can lead to inconsistencies across different projects. Angular’s structured approach provides a consistent development environment, making it easier to onboard new team members and maintain code quality.</p>
<h2>Community and Ecosystem</h2>
<p>Both React and Angular have vibrant communities and ecosystems. However, Angular’s all-encompassing nature often means that solutions and best practices are more standardized. This can be particularly helpful for new developers or those working in large teams.</p>
<h2>Example: Angular Community Resources</h2>
<ul>
<li>Angular Documentation: <a href="https://angular.io/docs">https://angular.io/docs</a></li>
<li>Angular Blog: <a href="https://blog.angular.io/">https://blog.angular.io/</a></li>
<li>Angular GitHub Repository: <a href="https://github.com/angular/angular">https://github.com/angular/angular</a></li>
</ul>
<p>These resources provide comprehensive guides, tutorials, and best practices, ensuring that developers have access to the information they need to build high-quality applications.</p>
<h2>Conclusion</h2>
<p>While React is an excellent choice for many projects due to its flexibility and performance, Angular’s comprehensive framework, TypeScript integration, and structured approach make it my go-to choice. It’s this structure and all-in-one nature that truly make Angular take my heart.</p>
<blockquote>
<p>“In the world of web development, choosing the right framework is about understanding your needs and aligning them with the strengths of the tool. For me, Angular’s structured approach and robust features make it a clear winner.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[SASS vs LESS: How to Choose the Best CSS Preprocessor for Your Projects]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/sass-vs-less</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/sass-vs-less</guid>
            <pubDate>Wed, 18 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Understanding the Differences and Benefits of SASS and LESS for Efficient CSS Development</p>
<img alt="Article on SASS vs LESS" loading="lazy" width="1587" height="885" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsass-vs-less.da47aa03.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsass-vs-less.da47aa03.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsass-vs-less.da47aa03.png&amp;w=3840&amp;q=75">
<p>When it comes to writing clean, maintainable, and reusable CSS, preprocessors such as SASS and LESS have grown popular among developers. Both of these tools allow you to write CSS more dynamically, with capabilities like variables, nesting, and mixins. But how can you choose which one is best for your project? Let’s look at the fundamental differences and benefits of SASS and LESS so you can make an informed decision.</p>
<h2>Why use a CSS preprocessor?</h2>
<p>A CSS preprocessor is a scripting language that enhances CSS and enables you to build more ordered, modular code. After writing, this code is compiled into standard CSS, which browsers then interpret.</p>
<h2>Benefits include:</h2>
<p><strong>Variables:</strong> Reuse values across the stylesheet.
<strong>Nesting</strong>: Arrange your CSS in a more logical, hierarchical order.
<strong>Mixins and Functions:</strong> Use mixins and functions to create reusable code blocks.
<strong>Partials:</strong> Split CSS into distinct files and import as needed.</p>
<p>Let’s take a closer look at SASS and LESS.</p>
<h2>What is SASS?</h2>
<p>SASS (Syntactically Awesome Style Sheets) is a popular preprocessor noted for its advanced capabilities. It has two syntaxes: the original SASS (which utilizes indentation and no semicolons) and the more popular SCSS (which is comparable to conventional CSS with curly brackets and semicolons).</p>
<h2>Key Features of SASS:</h2>
<p><strong>Nesting:</strong> Allows for better organization of CSS rules.</p>
<pre class="language-sass"><code class="language-sass"><span class="token selector">.container {</span>
  <span class="token selector">.header {</span>
<span class="token property-line">    <span class="token property">background-color</span><span class="token punctuation">:</span> blue;</span>
  <span class="token selector">}</span>
<span class="token selector">}</span>
</code></pre>
<p><strong>Variables:</strong> Store reusable values like colors, fonts, and dimensions.</p>
<pre class="language-sass"><code class="language-sass"><span class="token variable-line"><span class="token variable">$primary-color</span><span class="token punctuation">:</span> #3498db;</span>
<span class="token selector">body {</span>
<span class="token property-line">  <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token variable">$primary-color</span>;</span>
<span class="token selector">}</span>
</code></pre>
<p><strong>Mixins:</strong> Create reusable pieces of code.</p>
<pre class="language-sass"><code class="language-sass"><span class="token atrule-line"><span class="token atrule">@mixin</span> box-shadow($shadow) {</span>
<span class="token property-line">  <span class="token property">box-shadow</span><span class="token punctuation">:</span> <span class="token variable">$shadow</span>;</span>
<span class="token selector">}</span>
<span class="token selector">.card {</span>
<span class="token atrule-line">  <span class="token atrule">@include</span> box-shadow(0px 2px 5px rgba(0, 0, 0, 0.2));</span>
<span class="token selector">}</span>
</code></pre>
<p><strong>Functions:</strong> Write functions for calculations or logic.
<strong>Extensibility:</strong> Ability to extend other selectors for better code reuse.</p>
<h2>What is LESS?</h2>
<p>LESS (Leaner Style Sheets) is another popular preprocessor that takes a leaner approach but yet offers powerful capabilities. LESS syntax is more closely linked with CSS, making it easier for beginners to use.</p>
<h2>Key Features of LESS:</h2>
<p><strong>Variables:</strong> Like SASS, LESS allows the use of variables for easy code maintenance.</p>
<pre class="language-less"><code class="language-less"><span class="token variable">@primary-color<span class="token punctuation">:</span></span> <span class="token hexcode color">#3498db</span><span class="token punctuation">;</span>
<span class="token selector">body</span> <span class="token punctuation">{</span>
  <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token variable">@primary-color</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><strong>Nesting:</strong> LESS offers nested selectors to represent a hierarchical structure.</p>
<pre class="language-less"><code class="language-less"><span class="token selector">.container</span> <span class="token punctuation">{</span>
  <span class="token selector">.header</span> <span class="token punctuation">{</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token color">blue</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p><strong>Mixins:</strong> Write reusable blocks of CSS.</p>
<pre class="language-less"><code class="language-less"><span class="token selector">.box-shadow (<span class="token variable">@shadow</span>)</span> <span class="token punctuation">{</span>
  <span class="token property">box-shadow</span><span class="token punctuation">:</span> <span class="token variable">@shadow</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.card</span> <span class="token punctuation">{</span>
  <span class="token mixin-usage function">.box-shadow</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token unit">px</span> <span class="token number">2</span><span class="token unit">px</span> <span class="token number">5</span><span class="token unit">px</span> <span class="token color"><span class="token function">rgba</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.2</span><span class="token punctuation">)</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><strong>Functions:</strong> LESS supports built-in functions for mathematical operations and more.</p>
<h2>Key Differences Between SASS and LESS:</h2>
<h2>Syntax and Complexity:</h2>
<p>SASS supports both SCSS (similar to CSS) and indented SASS syntax, providing developers with flexibility.
LESS’ syntax is simpler and closer to vanilla CSS, making it easier for beginners.</p>
<h2>Features and Flexibility:</h2>
<p>SASS is known for its extensive feature set, including powerful extensions and improved CSS output control.
LESS is more minimalist, however it may not offer the same depth of functionality as SASS.</p>
<h2>Community and Ecosystem:</h2>
<p>SASS’s broader community provides access to more libraries, resources, and assistance.
While LESS is still actively used, its ecosystem is not as large.</p>
<h2>When to Choose SASS.</h2>
<p>If you require a more robust, flexible tool with advanced functionality and intend to scale your project in the future, SASS is the best choice. It is ideal for large-scale applications that require intricate styling and modularity.</p>
<h2>When to Choose Less.</h2>
<p>If you’re working on a smaller project or are new to preprocessors, LESS may be easier to get started with because of its simplicity and resemblance to vanilla CSS.</p>
<h2>Conclusion</h2>
<p>Both SASS and LESS have advantages and serve different project requirements. SASS is the ideal option if you want flexibility, advanced functionality, and extensive community support. If simplicity and ease of understanding are more crucial to your project, LESS will be a good fit.</p>
<blockquote>
<p>“The right tool for the job isn’t always the most powerful — it’s the one that makes your work efficient and your code maintainable.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[SQL vs. NoSQL: Navigating the Classic Database Dilemma]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/sql-vs-nosql-navigating-the-classic-database-dilemma</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/sql-vs-nosql-navigating-the-classic-database-dilemma</guid>
            <pubDate>Wed, 31 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Understanding the Core Differences and Making the Right Choice for Your Project</p>
<img alt="image representing sql vs nosql database" loading="lazy" width="1285" height="900" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsql-vs-nosql-navigating-the-classic-database-dilemma.ab0baa61.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsql-vs-nosql-navigating-the-classic-database-dilemma.ab0baa61.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fsql-vs-nosql-navigating-the-classic-database-dilemma.ab0baa61.png&amp;w=3840&amp;q=75">
<p>In the ever-evolving landscape of database management, choosing between SQL (Structured Query Language) and NoSQL (Not Only SQL) can be a daunting task. This classic dilemma often leaves developers and database administrators scratching their heads, trying to determine the best fit for their projects. To navigate this complex decision, it’s crucial to understand the fundamental differences, advantages, and use cases of both SQL and NoSQL databases.</p>
<h2>Structured Query Language (SQL): The Backbone of Relational Databases</h2>
<p>SQL databases, also known as relational databases, have been the cornerstone of data management for decades. They are designed to handle structured data, which is organized into tables with predefined schemas. Each table consists of rows and columns, and relationships between tables are established through keys.</p>
<p>Key Characteristics of SQL Databases:</p>
<ol>
<li><strong>Structured Schema:</strong> SQL databases require a well-defined schema, which means the structure of the data is known in advance.</li>
<li><strong>ACID Compliance:</strong> SQL databases adhere to ACID (Atomicity, Consistency, Isolation, Durability) properties, ensuring reliable transactions.</li>
<li><strong>SQL Language:</strong> SQL is a powerful and standardized language used for querying and managing data.</li>
<li><strong>Scalability:</strong> SQL databases typically scale vertically, meaning increasing capacity often involves upgrading the existing hardware.</li>
</ol>
<p>Popular SQL Databases:</p>
<ul>
<li><strong>MySQL:</strong> Open-source and widely used for web applications.</li>
<li><strong>PostgreSQL:</strong> Known for its advanced features and compliance with SQL standards.</li>
<li><strong>SQLite:</strong> Lightweight and often used in embedded systems and mobile applications.</li>
<li><strong>Microsoft SQL Server:</strong> Enterprise-level database management system with robust security features.</li>
</ul>
<h2>NoSQL: Embracing Flexibility and Scalability</h2>
<p>NoSQL databases emerged as a response to the limitations of traditional relational databases, particularly in handling large volumes of unstructured data and horizontal scalability. Unlike SQL databases, NoSQL databases do not require a fixed schema, allowing for greater flexibility.</p>
<p>Key Characteristics of NoSQL Databases:</p>
<ol>
<li><strong>Schema-less Design:</strong> NoSQL databases can store data without a predefined schema, making them ideal for unstructured or semi-structured data.</li>
<li><strong>Eventual Consistency:</strong> While SQL databases focus on consistency, NoSQL databases often prioritize availability and partition tolerance, leading to eventual consistency.</li>
<li><strong>Horizontal Scalability:</strong> NoSQL databases are designed to scale out by adding more servers, which is essential for handling big data and high-traffic applications.</li>
<li><strong>Diverse Data Models:</strong> NoSQL encompasses various database types, including document, key-value, column-family, and graph databases.</li>
</ol>
<p>Popular NoSQL Databases:</p>
<ul>
<li><strong>MongoDB:</strong> Document-oriented database known for its flexibility and scalability.</li>
<li><strong>Cassandra:</strong> Column-family database designed for high availability and fault tolerance.</li>
<li><strong>Redis:</strong> In-memory key-value store used for caching and real-time analytics.</li>
<li><strong>Neo4j:</strong> Graph database optimized for handling relationships and interconnected data.</li>
</ul>
<h2>Choosing the Right Database: Key Considerations</h2>
<p>The decision between SQL and NoSQL hinges on several factors, including the nature of the data, scalability requirements, and specific use cases.</p>
<ol>
<li><strong>Data Structure:</strong> If your data is highly structured and relational, SQL databases are a natural fit. For unstructured or semi-structured data, NoSQL databases offer the necessary flexibility.</li>
<li><strong>Scalability Needs:</strong> For applications requiring horizontal scalability and handling large volumes of data, NoSQL databases are often the better choice.</li>
<li><strong>Consistency vs. Availability:</strong> SQL databases are ideal for applications where consistency and transaction integrity are critical. In contrast, NoSQL databases prioritize availability and partition tolerance, making them suitable for distributed systems.</li>
<li><strong>Use Cases:</strong></li>
</ol>
<ul>
<li><strong>SQL:</strong> Financial systems, enterprise applications, and situations requiring complex queries.</li>
<li><strong>NoSQL:</strong> Big data analytics, content management systems, and applications with dynamic data models.</li>
</ul>
<h2>Conclusion</h2>
<p>The choice between SQL and NoSQL databases is not a one-size-fits-all decision. It requires a thorough understanding of your project’s requirements, data structure, and scalability needs. By carefully evaluating these factors, you can make an informed choice that aligns with your goals and ensures optimal performance.</p>
<blockquote>
<p>“Choosing the right database is like selecting the right tool for the job. It’s not about which is better, but which is best suited for your specific needs.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[The Impact of Web Components on Modern Frontend Development]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/the-game-changing-impact-of-web-components</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/the-game-changing-impact-of-web-components</guid>
            <pubDate>Wed, 09 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-chronicles/revolutionizing-frontend-the-game-changing-impact-of-web-components-937a8c640af8?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*Y7hRef-9A-W9a9oMpgkWIw.png" alt=""></a></p>
<p>How Web Components are Reshaping Modern Frontend Development</p>
<p>The way we build user interfaces (UIs) has evolved significantly over the years, and one of the most important innovations driving this evolution is Web Components. This powerful set of native browser features allows developers to create reusable, encapsulated, and framework-independent UI elements, making it a game-changer in modern frontend development.</p>
<h2>What Are Web Components?</h2>
<p>Web Components are a set of standards that allow developers to create custom, reusable HTML tags that work seamlessly across all browsers and frameworks. These standards consist of three key technologies:</p>
<ol>
<li>Custom Elements: Enable developers to define new HTML tags.</li>
<li>Shadow DOM: Provides encapsulation for HTML and CSS, ensuring that a component’s internal structure and styling are isolated from the rest of the document.</li>
<li>HTML Templates: Allow developers to define reusable chunks of HTML that can be instantiated multiple times without polluting the global scope.</li>
</ol>
<p>By leveraging these core features, developers can create self-contained components that can be easily integrated into any web application.</p>
<h2>The Evolution of Frontend Development</h2>
<p>Traditionally, building a frontend UI required either vanilla JavaScript or a framework like Angular, React, or Vue.js. These frameworks introduced their own ways to build reusable components, which often led to framework lock-in — meaning that switching between frameworks could require rewriting large portions of the UI codebase.</p>
<p>Web Components break this cycle by providing a framework-agnostic approach to building UIs. A Web Component, once created, can be used across different projects and frameworks, dramatically reducing the overhead of migrating or mixing technologies.</p>
<h2>The Benefits of Web Components</h2>
<h2>1. Reusability</h2>
<p>One of the greatest advantages of Web Components is their reusability. Once a Web Component is developed, it can be reused across multiple projects or even different teams. This promotes consistency in UI elements and reduces development time, as developers no longer need to reinvent the wheel when building standard components like buttons, input fields, or even entire navigation bars.</p>
<h2>2. Framework Independence</h2>
<p>Unlike components built using JavaScript frameworks, Web Components can be used with any frontend stack, whether it’s React, Angular, Vue, or even plain JavaScript. This framework independence means developers are no longer tied to the limitations or updates of a particular framework.</p>
<h2>3. Encapsulation</h2>
<p>With Web Components, each element can have its own Shadow DOM, which ensures that its internal structure and styles are encapsulated. This is a huge step forward for maintaining style consistency across applications, as it prevents CSS conflicts and ensures that a component’s internal styling doesn’t leak into the global stylesheet or get affected by external styles.</p>
<h2>4. Simplified Maintenance</h2>
<p>Since Web Components are based on standard web technologies (HTML, CSS, JavaScript), they are easy to maintain. There is no need to learn a new library or framework, and they will continue to work as browsers evolve, providing long-term stability.</p>
<h2>Real-World Use Cases</h2>
<p>Companies like Google, GitHub, and Salesforce have already embraced Web Components to develop large-scale, complex UIs. For instance:</p>
<ul>
<li>Google’s Polymer Project heavily promotes the use of Web Components, enabling developers to build sophisticated UIs with ease.</li>
<li>Salesforce’s Lightning Web Components (LWC) uses Web Components under the hood, allowing Salesforce developers to create reusable components across their platform.</li>
<li>GitHub’s contribution to the Web Component community includes the creation of several open-source libraries that utilize Web Components for internal features.</li>
</ul>
<h2>Are Web Components the Future of Frontend Development?</h2>
<p>Web Components represent a significant shift in how we think about and build web applications. By decoupling the development of UI elements from specific frameworks, they enable a more flexible, maintainable, and future-proof approach to frontend development.</p>
<p>However, like any technology, they are not without their challenges. For example, while Web Components are supported by most modern browsers, there are still some compatibility issues with older versions, and managing large-scale applications with many components can become complex without a well-thought-out architecture.</p>
<h2>When to Use Web Components</h2>
<p>While Web Components offer numerous advantages, they may not be the right solution for every project. Here are a few scenarios where Web Components might be particularly beneficial:</p>
<ul>
<li>Cross-Framework Compatibility: If your project needs to support multiple frontend frameworks or micro-frontend architecture, Web Components are an ideal choice.</li>
<li>Library of Reusable UI Elements: If you’re developing a design system or reusable component library for use across various projects, Web Components allow you to create elements that are truly framework-independent.</li>
<li>Legacy System Integration: If you’re integrating modern UI elements into a legacy system, Web Components provide a non-intrusive way to enhance the existing system without requiring a complete overhaul.</li>
</ul>
<h2>Conclusion</h2>
<p>Web Components are revolutionizing frontend development by providing developers with a powerful toolset to build encapsulated, reusable, and framework-independent UI elements. As the industry continues to embrace them, they are set to play a crucial role in the future of web development, offering flexibility and consistency across platforms.</p>
<p>As you consider adopting Web Components, remember that their true power lies in reusability and interoperability, enabling you to build applications that are maintainable, scalable, and future-proof.</p>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[The Rise of Progressive Web Apps: Unifying the Web and Mobile Experience]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/the-rise-of-progressive-web-apps</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/the-rise-of-progressive-web-apps</guid>
            <pubDate>Sat, 17 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>How Progressive Web Apps Are Transforming User Interaction Across Devices</p>
<img alt="Article on PWA" loading="lazy" width="1286" height="903" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-rise-of-progressive-web-apps.c4e2f699.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-rise-of-progressive-web-apps.c4e2f699.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-rise-of-progressive-web-apps.c4e2f699.png&amp;w=3840&amp;q=75">
<p>In today’s fast-paced digital environment, businesses are continuously looking for methods to engage users across many platforms. With an increasing number of mobile users, providing seamless experiences across the web and mobile has become critical. Progressive Web Apps (PWAs) are a groundbreaking technology that bridges the gap between web and mobile, providing the best of both worlds.</p>
<h2>What Are Progressive Web Apps?</h2>
<p>Progressive Web Apps (PWAs) are web applications that use modern web technology to provide an app-like experience. Unlike typical mobile apps, which must be downloaded from app stores, PWAs are available via a web browser and can be installed directly from the website. This makes them more accessible and offers the convenience of a native app without the hassle of app store submissions.</p>
<h2>Key Features of Progressive Web Apps</h2>
<p><strong>Offline Access:</strong> Service workers cache key assets and data, allowing PWAs to function offline or on low-quality networks. This offers a constant user experience even when the connection is shaky.</p>
<p><strong>Push Notifications:</strong> PWAs, like native apps, may send push notifications to re-engage users, making them an effective tool for organizations seeking to sustain user connection.</p>
<p><strong>Responsive Design:</strong> PWAs are fully responsive, responding to a wide range of screen sizes and devices, from smartphones to desktops, to provide a consistent user experience.</p>
<p><strong>Installation without App Stores:</strong> Users can easily install PWAs by adding them to their home screen, eliminating the requirement for an app store. This lowers friction and speeds up app access.</p>
<p><strong>Secure by Default:</strong> PWAs are served via HTTPS, guaranteeing that all communications between the user and the app are encrypted.</p>
<h2>The Impact of PWAs on Businesses</h2>
<p>Many organizations have already started using PWAs to increase user engagement and retention. Companies such as Twitter, Pinterest, and Starbucks have claimed significant gains in user involvement and conversion rates since launching PWAs. Twitter’s PWA, Twitter Lite, resulted in a 65% increase in pages per session, while user engagement on Pinterest increased by 40%.</p>
<h2>Advantages Over Native Apps</h2>
<p><strong>Cost-Effective Development:</strong> Developing a PWA is generally less expensive than generating distinct native apps for iOS and Android. A single codebase may support both online and mobile users.</p>
<p><strong>Faster Load Times:</strong> PWAs are designed for speed, frequently loading in a quarter of the time it takes a native app to load, resulting in a better user experience.</p>
<p><strong>No Installation Barriers:</strong> By eliminating the need to visit an app store, PWAs lower installation barriers, allowing consumers to access the app immediately.</p>
<p><strong>Easy Updates:</strong> PWA updates are smooth and do not require users to download new versions from the App Store. When users open the app, they are always presented with the most recent update.</p>
<h2>The Future of Progressive Web Apps</h2>
<p>As mobile usage increases, so will the desire for smooth and efficient digital experiences. PWAs are on track to become the industry standard for web and mobile development, providing organizations with a compelling approach to engage users across multiple platforms. With digital titans like as Google and Microsoft endorsing PWAs, the technology is here to stay, and its popularity will only rise.</p>
<h2>Conclusion</h2>
<p>Progressive Web Apps (PWAs) represent the future of web and mobile integration, offering a seamless experience that combines web accessibility with mobile app capability. Investing in PWA technology is a must for firms trying to stay ahead of the digital curve.</p>
<blockquote>
<p>“In a world where users demand seamless experiences, Progressive Web Apps are the bridge that connects the best of web and mobile.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[TypeScript: The Essential Tool for Modern JavaScript Development]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/typeScript-the-beauty-with-brains-in-modern-javaScript-evelopment</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/typeScript-the-beauty-with-brains-in-modern-javaScript-evelopment</guid>
            <pubDate>Wed, 14 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Unlocking the Power of TypeScript for Cleaner, More Reliable Code</p>
<img alt="Article on TypeScript" loading="lazy" width="1287" height="902" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2FtypeScript-the-beauty-with-brains-in-modern-javaScript-evelopment.c26e4524.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2FtypeScript-the-beauty-with-brains-in-modern-javaScript-evelopment.c26e4524.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2FtypeScript-the-beauty-with-brains-in-modern-javaScript-evelopment.c26e4524.png&amp;w=3840&amp;q=75">
<p>Efficiency and dependability are crucial in the quick-paced field of web development. As developers, we’re always looking for tools that will improve the robustness of our code while still making it elegant and simple to maintain. A clever and elegant answer is provided by TypeScript, a language that combines the rigor of static typing with the flexibility of JavaScript.</p>
<h2>TypeScript: What Is It?</h2>
<p>Microsoft developed TypeScript, which is a superset of JavaScript that includes static types. This makes your code more predictable and debug-friendly by allowing you to define the types of variables, functions, and objects. Variables in JavaScript are dynamically typed, meaning they can change types; in contrast, TypeScript enforces types, allowing problems to be discovered early in the development process.</p>
<h2>The Reasons TypeScript Is Not Just a Superset</h2>
<p>Although TypeScript appears to be merely another layer of complexity at first, it actually has a number of advantages that speed up development, that include:</p>
<p><strong>Improved Code Quality:</strong> TypeScript’s static typing allows programmers to identify possible mistakes early in the development process, as opposed to at runtime. A more seamless development process and fewer bugs result from this.</p>
<p><strong>Better Developer Experience:</strong> TypeScript’s strong type inference makes it possible for the language to comprehend types even in cases when they aren’t defined explicitly, which facilitates reading and writing code.</p>
<p><strong>Improved Cooperation:</strong> TypeScript functions as a self-documenting code format in larger organizations. Without having to sift through documentation or rely only on intuition, developers may determine what a function or variable is intended to do.</p>
<p><strong>Scalability:</strong> Keeping up with the codebase gets harder as projects get bigger. Because of TypeScript’s disciplined methodology, scalable and maintainable code is guaranteed to last as the project grows.</p>
<p><strong>Smooth Integration with JavaScript:</strong> TypeScript code can be used in any environment that supports JavaScript because it compiles to ordinary JavaScript. One by one, you can convert files in your current JavaScript projects to incorporate TypeScript progressively.</p>
<h2>TypeScript in Action: Real-World Examples</h2>
<p>Asana, Slack, Airbnb, and many more top internet businesses have all embraced TypeScript. These businesses use TypeScript to decrease defects, expedite development, and increase the dependability of their codebase.</p>
<p>For instance, TypeScript is the primary language of the well-known front-end framework Angular, demonstrating how TypeScript can be used to create intricate, scalable applications.</p>
<h2>How to Get Started with TypeScript</h2>
<p>Getting started with TypeScript is simple. Here’s a basic example:</p>
<pre class="language-typescript"><code class="language-typeScript"><span class="token keyword">function</span> <span class="token function">add</span><span class="token punctuation">(</span>a<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> b<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">return</span> a <span class="token operator">+</span> b<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">let</span> sum <span class="token operator">=</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>sum<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Outputs 15</span>
</code></pre>
<p>In this example, the function add takes two numbers as arguments and returns a number. TypeScript checks that only numbers are passed to the function, ensuring that the function behaves as expected.</p>
<p>To start using TypeScript in your project:</p>
<ol>
<li>Install TypeScript using npm:</li>
</ol>
<pre class="language-bash"><code class="language-bash"><span class="token function">npm</span> <span class="token function">install</span> -g typescript
</code></pre>
<ol start="2">
<li>Compile a TypeScript file to JavaScript:</li>
</ol>
<pre class="language-bash"><code class="language-bash">tsc filename.ts
</code></pre>
<ol start="3">
<li>Integrate TypeScript with modern frameworks like Angular, React, or Node.js to leverage its full potential.</li>
</ol>
<h2>To sum up</h2>
<p>TypeScript is more than just a JavaScript type addition tool. It’s an architectural change that gives your code scalability, safety, and structure. Developers may write cleaner, more dependable code, which reduces defects and speeds up development cycles, by embracing TypeScript. To put it briefly, TypeScript is a crucial component of any current developer’s toolset since it is the ideal fusion of intelligence and style.</p>
<blockquote>
<p>“TypeScript is the bridge that connects JavaScript’s dynamic nature with the stability of static typing — empowering developers to write code that’s as elegant as it is efficient.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Understanding JavaScript Hoisting: The Hidden Behavior]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/understanding-javaScript-hoisting-the-hidden-behavior</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/understanding-javaScript-hoisting-the-hidden-behavior</guid>
            <pubDate>Mon, 07 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><img src="https://cdn-images-1.medium.com/max/1024/1*hZXP8FqJ3GmiNMPI9mG4jw.png" alt=""></p>
<p>Unraveling the Mysteries of JavaScript Hoisting: How Variable and Function Declarations Really Work</p>
<p>JavaScript hoisting is a fundamental concept that often confounds newcomers to the language while also presenting intriguing complexities for more experienced developers. It’s a behavior where variable and function declarations are moved to the top of their respective scopes during the compilation phase, before the code is executed. This can lead to some unexpected results if you’re not aware of how it works. Let’s dive deep into this quirky feature of JavaScript and unravel its mysteries, starting from the basics and progressing to more advanced concepts.</p>
<h2>What is Hoisting?</h2>
<p>In simple terms, hoisting is JavaScript’s default behavior of moving declarations to the top. This means that regardless of where variables and functions are declared in the code, they are moved to the top of their scope. However, it’s crucial to understand that only the declarations are hoisted, not the initializations.</p>
<p>For example, consider this code:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</code></pre>
<p>You might expect this to throw an error, but it actually outputs ‘undefined’. This is because the declaration of ‘x’ is hoisted to the top, but not its initialization. The code is interpreted as:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">var</span> x<span class="token punctuation">;</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</code></pre>
<h2>Variable Hoisting</h2>
<p>Variables declared with ‘var’ are hoisted to the top of their scope and initialized with a value of ‘undefined’. However, it’s important to note that variables declared with ‘let’ and ‘const’ are hoisted but not initialized. This leads to a “temporal dead zone” where accessing these variables before their declaration results in a ReferenceError.</p>
<h2>Function Hoisting</h2>
<p>Function declarations are also hoisted, and unlike variables, they are hoisted completely. This means you can call a function before it appears in your code:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token function">sayHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">sayHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">"Hello, world!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>This works perfectly fine because the entire function declaration is hoisted. However, function expressions are not hoisted in the same way:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token function">sayHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// TypeError: sayHello is not a function</span>

<span class="token keyword">var</span> <span class="token function-variable function">sayHello</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">"Hello, world!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<h2>The Pitfalls of Hoisting</h2>
<p>While hoisting can sometimes be convenient, it can also lead to confusion and bugs if not properly understood. It’s generally considered good practice to declare variables at the top of their scope and functions before they are used to avoid any unexpected behavior.</p>
<h2>Best Practices to Avoid Hoisting Issues</h2>
<ol>
<li>Always declare variables at the top of their scope.</li>
<li>Use ‘let’ and ‘const’ instead of ‘var’ to avoid hoisting-related issues.</li>
<li>Declare functions before calling them, even though function declarations are hoisted.</li>
<li>Be aware of the differences between function declarations and function expressions.</li>
</ol>
<h2>Advanced Concepts in Hoisting</h2>
<p>Now that we’ve covered the basics, let’s delve into some more advanced aspects of hoisting that can give you a deeper understanding of this JavaScript behavior.</p>
<h2>The Temporal Dead Zone (TDZ)</h2>
<p>The Temporal Dead Zone is a behavior associated with block-scoped variables (let and const) that occurs between the start of a block and the point at which the variable is declared. During this period, accessing the variable will result in a ReferenceError. This is different from variables declared with var, which are initialized with undefined when hoisted.</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token punctuation">{</span>
    <span class="token comment">// TDZ starts here</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ReferenceError</span>
    <span class="token keyword">let</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span> <span class="token comment">// TDZ ends here</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Understanding the TDZ is crucial for avoiding subtle bugs in your code, especially when refactoring var declarations to let or const.</p>
<h2>Hoisting in Class Declarations</h2>
<p>While classes in JavaScript are essentially “special functions”, they have some unique hoisting behavior. Like function declarations, class declarations are hoisted. However, they remain uninitialized until evaluation, similar to let and const declarations. This means you can’t use a class before its declaration in the code.</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">const</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ReferenceError</span>

<span class="token keyword">class</span> <span class="token class-name">Rectangle</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre>
<h2>Function Expressions vs. Arrow Functions</h2>
<p>It’s important to understand the difference in hoisting behavior between various function types:</p>
<ol>
<li>Function declarations are fully hoisted.</li>
<li>Function expressions using var are hoisted, but only the variable declaration, not the function assignment.</li>
<li>Arrow functions, being a form of function expression, follow the same rules as function expressions.</li>
</ol>
<pre class="language-javascript"><code class="language-javascript"><span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>declaredFunc<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [Function: declaredFunc]</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>varFunc<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// undefined</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>letFunc<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ReferenceError</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>arrowFunc<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// undefined</span>

<span class="token keyword">function</span> <span class="token function">declaredFunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">var</span> <span class="token function-variable function">varFunc</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> <span class="token function-variable function">letFunc</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> <span class="token function-variable function">arrowFunc</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=&gt;</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<h2>Hoisting in Modules</h2>
<p>In ES6 modules, hoisting works slightly differently. While declarations are still hoisted within modules, they are not accessible until the import statement is encountered. This helps to maintain the integrity of the module system and prevents circular dependencies.</p>
<h2>The ‘typeof’ Operator and Hoisting</h2>
<p>An interesting quirk of hoisting involves the typeof operator. For variables declared with var, typeof will return ‘undefined’ even if the variable is accessed before its declaration. However, for let and const, typeof will throw a ReferenceError if used in the TDZ.</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> undeclaredVar<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 'undefined'</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> declaredLater<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 'undefined'</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> notDeclared<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 'undefined'</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> blockScoped<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ReferenceError</span>

<span class="token keyword">var</span> declaredLater<span class="token punctuation">;</span>
<span class="token keyword">let</span> blockScoped<span class="token punctuation">;</span>
</code></pre>
<h2>Hoisting in Conditional Statements</h2>
<p>Function declarations within conditional statements are hoisted, but their behavior can be unpredictable and is not consistent across all JavaScript engines. It’s best to avoid declaring functions within conditional statements.</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// This might work, but it's not guaranteed</span>

<span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">function</span> <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">"I'm defined!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Performance Implications</h2>
<p>While hoisting is a language feature and not directly related to performance, understanding it can lead to more optimized code. By declaring variables and functions at the top of their scope, you’re aligning your code with how JavaScript interprets it, potentially leading to slight performance improvements and certainly to more readable and maintainable code.</p>
<h2>Conclusion</h2>
<p>Understanding hoisting is crucial for writing clean, bug-free JavaScript code. While it might seem like a quirky feature, it’s an integral part of how JavaScript works under the hood. By being aware of hoisting and following best practices, you can write more predictable and maintainable code.</p>
<p>Hoisting in JavaScript is more than just moving declarations to the top. It involves complex interactions between scopes, the temporal dead zone, and different types of declarations. By understanding these intricacies, you can write more robust and predictable JavaScript code, avoid common pitfalls, and even optimize your code’s performance.</p>
<p>Remember, JavaScript’s behavior might not always be intuitive, but with a solid understanding of concepts like hoisting, you’ll be better equipped to harness the full power of the language. While hoisting is a powerful feature of JavaScript, it’s often best to write your code as if hoisting didn’t exist, explicitly declaring variables and functions before using them. This practice leads to clearer, more maintainable code that’s less prone to unexpected behavior.</p>
<p>Happy coding, and may your JavaScript journey be free of hoisting-related bugs!</p>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a>
<em>If you like this article, please think about buying me a coffee☕.</em></p>
<h3>Burhanuddin’s Code Chronicles</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-chronicles"><strong><em>Burhanuddin’s Code Chronicles</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏 <strong>️️</strong></li>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Visit our other platforms: <a href="https://dev.to/burhanuddin"><strong>Dev.to</strong></a> | <a href="https://deepstash.com/u/burhanuddinhb"><strong>Deepstash</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-chronicles"><strong>Burhanuddin’s Code Chronicles</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Mastering Async/Await in JavaScript: Simplifying Asynchronous Code]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/unlocking-power-of-async-await-in-javascript</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/unlocking-power-of-async-await-in-javascript</guid>
            <pubDate>Wed, 04 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Learn how to streamline your asynchronous JavaScript code with Async/Await, making it more readable, maintainable, and efficient.</p>
<img alt="Article on Async-Await in JS" loading="lazy" width="1283" height="902" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Funlocking-power-of-async-await-in-javascript.cfed2e71.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Funlocking-power-of-async-await-in-javascript.cfed2e71.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Funlocking-power-of-async-await-in-javascript.cfed2e71.png&amp;w=3840&amp;q=75">
<p>Handling asynchronous activities in JavaScript can quickly become complex and difficult to manage. Traditionally, callbacks and promises were the go-to solutions, but they came with their own set of issues, such as callback hell and promise chaining. Async/Await is a current way for simplifying asynchronous code, making it more legible and maintainable.</p>
<h2>The Need for Async/Await.</h2>
<p>Before delving into the complex workings of Async/Await, it’s important to understand what problem it solves. Asynchronous code is critical in JavaScript, particularly when dealing with tasks like as API calls, file I/O, and timers. Promises enhanced the way we handled these processes by providing a more controllable structure. However, promise chains may still grow complicated.</p>
<p>To solve these complications, ES2017 (ECMAScript 8) includes async/await, which allows developers to write asynchronous code that appears and performs like synchronous code.</p>
<h2>Understanding Async/Await.</h2>
<p>Async/Await is fundamentally based on promises. The async keyword defines an asynchronous function, and the await keyword can be used within this function to suspend execution until a promise is resolved or refused.</p>
<p>Here’s a simple example to illustrate:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">fetchData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword control-flow">try</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> response <span class="token operator">=</span> <span class="token keyword control-flow">await</span> <span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://api.example.com/data'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> data <span class="token operator">=</span> <span class="token keyword control-flow">await</span> response<span class="token punctuation">.</span><span class="token method function property-access">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span> <span class="token keyword control-flow">catch</span> <span class="token punctuation">(</span>error<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">error</span><span class="token punctuation">(</span><span class="token string">'Error fetching data:'</span><span class="token punctuation">,</span> error<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token function">fetchData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>In this example, the fetchData function is declared async, indicating that it is asynchronous. Inside the function, the await keyword is used to wait for the fetch promise to resolve before proceeding to the next line of code. If the promise is refused, the catch block addresses the error, which prevents further promise rejections.</p>
<h2>Advantages of Async/Await</h2>
<p><strong>Improved Readability:</strong> Improved code readability is the primary benefit. It removes the requirement for chaining.then() calls make the code appear cleaner and easier to grasp.</p>
<p><strong>Error Handling:</strong> Async/Await simplifies error handling, making it equivalent to synchronous programming. You can handle errors using try/catch blocks, which is more straightforward than dealing with errors directly.Catch() in promise chains.</p>
<p><strong>Synchronous-Like Flow:</strong> Despite being asynchronous, the flow of code written with Async/Await appears synchronous, making it easier to reason about, particularly for those unfamiliar with asynchronous programming.</p>
<p><strong>Easier Debugging:</strong> Debugging Async/Await code is often easier than dealing with promises. Stepping through the code with a debugger is easier because it appears to be synchronous.</p>
<p><strong>Real-World Example:</strong> Sequential vs. Concurrent Execution</p>
<p>Let’s take a practical example of fetching data from multiple APIs sequentially and concurrently to see how Async/Await can be utilized effectively.</p>
<p>Sequential Execution:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">fetchSequentially</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> data1 <span class="token operator">=</span> <span class="token keyword control-flow">await</span> <span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://api.example.com/data1'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">const</span> data2 <span class="token operator">=</span> <span class="token keyword control-flow">await</span> <span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://api.example.com/data2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword control-flow">return</span> <span class="token punctuation">[</span><span class="token keyword control-flow">await</span> data1<span class="token punctuation">.</span><span class="token method function property-access">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword control-flow">await</span> data2<span class="token punctuation">.</span><span class="token method function property-access">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Concurrent Execution:</p>
<pre class="language-javascript"><code class="language-javaScript"><span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">fetchConcurrently</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>data1<span class="token punctuation">,</span> data2<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword control-flow">await</span> <span class="token known-class-name class-name">Promise</span><span class="token punctuation">.</span><span class="token method function property-access">all</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://api.example.com/data1'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://api.example.com/data2'</span><span class="token punctuation">)</span>
  <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword control-flow">return</span> <span class="token punctuation">[</span><span class="token keyword control-flow">await</span> data1<span class="token punctuation">.</span><span class="token method function property-access">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword control-flow">await</span> data2<span class="token punctuation">.</span><span class="token method function property-access">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>In the sequential example, each request waits for the preceding one to finish. This can be slow if the operations are independent. In contrast, the concurrent example initiates both requests at the same time, considerably enhancing performance when the actions are independent of one another.</p>
<h2>Common Pitfalls and Best Practices</h2>
<p>While Async/Await makes asynchronous coding easier, there are certain frequent dangers to be mindful of:</p>
<p><strong>Forgetting await:</strong> If you forget to use await before a promise, the function will return a promise rather than the resolved value, which may result in unexpected behavior.</p>
<p><strong>Nested Asynchronous Calls:</strong> Avoid highly nested asynchronous functions, as they can still result in complex code. Refactor wherever possible to keep the structure flat.</p>
<p><strong>Error Handling:</strong> Always use try/catch to avoid unhandled promise rejections, especially in production code.</p>
<p><strong>Best practices:</strong></p>
<ul>
<li>To execute independent asynchronous activities in parallel, use Promise.all().</li>
<li>Keep your asynchronous code flat and avoid extensive nesting.</li>
<li>Always use try/catch to manage errors in your asynchronous functions.</li>
</ul>
<h2>Conclusion</h2>
<p>Async/Await is an extremely useful technique in the JavaScript developer’s toolkit. The ability to write asynchronous code that appears and feels like synchronous code enhances readability, maintainability, and overall developer experience. Mastering Async/Await allows you to write code that is clearer, more efficient, and easier to debug, resulting in more resilient JavaScript applications.</p>
<blockquote>
<p>“Writing asynchronous code doesn’t have to be a struggle. With Async/Await, you can make your code as smooth as a well-composed melody.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Enhancing Responsive Web Design Beyond Media Queries for Better User Experience]]></title>
            <link>https://burhanuddinhamzabhai.dev/articles/unlocking-the-power-of-responsive-web-design</link>
            <guid>https://burhanuddinhamzabhai.dev/articles/unlocking-the-power-of-responsive-web-design</guid>
            <pubDate>Wed, 25 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-chronicles/unlocking-the-power-of-responsive-web-design-beyond-media-queries-a208bd0e84ad?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*58fgbklZlyUXyP_U1J4Kyw.png" alt=""></a></p>
<p>Revolutionizing Web Design for Seamless User Experiences</p>
<p>In the world of web development, responsive design has become a must-have. Users expect websites to appear and work seamlessly on any device, whether it's a smartphone, tablet, or desktop. Traditionally, media queries have been the preferred method for building responsive designs. However, as devices improve, there is an increasing need to investigate solutions beyond media queries.</p>
<p>This article delves into cutting-edge strategies for improving your responsive design strategy, guaranteeing that your websites can adjust to any screen size or device without relying exclusively on media queries.</p>
<h2>Understanding the limitations of media queries.</h2>
<p>CSS relies heavily on media queries, which enable developers to apply styles based on device parameters such as screen width, resolution, and orientation. While immensely valuable, media queries can result in rigid architectures that fail under unforeseen circumstances. They also tend to focus on specific breakpoints, such as 768px for tablets and 1024px for desktops, which are no longer enough in an era of innumerable devices.</p>
<p>For example, a website created with specified breakpoints may not appear correctly on newer devices such as foldable phones or ultra-wide monitors. Furthermore, media queries may fail to account for dynamic scaling of browser windows, resulting in awkward transitions and disturbed user interactions.</p>
<h2>Embracing fluid design principles.</h2>
<p>Fluid design is one approach of overcoming the limits of media queries. In a fluid design, layout elements are assigned percentage values rather than fixed units such as pixels. This enables the elements to scale relative to the viewport or their parent containers, increasing the design's adaptability to different screen sizes.</p>
<p>Example:</p>
<pre class="language-css"><code class="language-css"><span class="token selector"><span class="token class">.container</span></span> <span class="token punctuation">{</span>
  <span class="token property">width</span><span class="token punctuation">:</span> <span class="token number">80</span><span class="token unit">%</span><span class="token punctuation">;</span> <span class="token comment">/* Instead of a fixed pixel width */</span>
  <span class="token property">padding</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token unit">%</span><span class="token punctuation">;</span> <span class="token comment">/* Fluid padding that adjusts with screen size */</span>
<span class="token punctuation">}</span>
</code></pre>
<p>This fluidity creates a more natural flow, with content adapting dynamically to changes in the viewport without the need for specific breakpoints.</p>
<h2>Leveraging Modern CSS Units</h2>
<p>Another technique to make your designs more responsive is to use contemporary CSS units like vw, vh, min(), max(), and clamp(). These units enable developers to construct layouts that dynamically scale with the size of the viewport, avoiding the need for predefined media queries.</p>
<p>Example using clamp():</p>
<pre class="language-css"><code class="language-css"><span class="token selector">h1</span> <span class="token punctuation">{</span>
  <span class="token property">font-size</span><span class="token punctuation">:</span> <span class="token function">clamp</span><span class="token punctuation">(</span><span class="token number">1.5</span><span class="token unit">rem</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token unit">vw</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token unit">rem</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>The clamp() function sets a minimum, preferred, and maximum size for elements, making it highly effective for scaling typography and other elements across different devices without breakpoints.</p>
<h2>Flexbox and Grid: the foundation of modern layouts</h2>
<p>Flexbox and CSS Grid have revolutionized responsive web design by providing strong layout technologies that easily adjust to different screen sizes. By structuring layouts with Flexbox or Grid, developers may construct responsive components that resize and reorganize themselves without the use of sophisticated media queries.</p>
<p>Flexbox Example:</p>
<pre class="language-css"><code class="language-css"><span class="token selector"><span class="token class">.flex-container</span></span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">flex-wrap</span><span class="token punctuation">:</span> wrap<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector"><span class="token class">.flex-item</span></span> <span class="token punctuation">{</span>
  <span class="token property">flex</span><span class="token punctuation">:</span> <span class="token number">1</span> <span class="token number">1</span> auto<span class="token punctuation">;</span>
  <span class="token property">margin</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token unit">px</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>With Flexbox, items automatically wrap based on available space, ensuring a smooth, responsive layout.</p>
<pre class="language-css"><code class="language-css"><span class="token selector"><span class="token class">.grid-container</span></span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> grid<span class="token punctuation">;</span>
  <span class="token property">grid-template-columns</span><span class="token punctuation">:</span> <span class="token function">repeat</span><span class="token punctuation">(</span>auto-fill<span class="token punctuation">,</span> <span class="token function">minmax</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token unit">px</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token unit">fr</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">gap</span><span class="token punctuation">:</span> <span class="token number">20</span><span class="token unit">px</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>CSS Grid allows developers to design complex, flexible layouts without hardcoding breakpoints. The auto-fill and minmax() features ensure that elements resize and reflow appropriately.</p>
<h2>Responsive Images: Optimizing for Performance</h2>
<p>Images are an important part of web design, and ensuring that they load quickly across devices is essential for a seamless user experience. Techniques such as srcset and the picture element allow responsive images to offer varying resolutions based on the device, eliminating unnecessary data usage.</p>
<p>Example:</p>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>image-800.jpg<span class="token punctuation">"</span></span> 
     <span class="token attr-name">srcset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>image-400.jpg 400w, image-800.jpg 800w, image-1200.jpg 1200w<span class="token punctuation">"</span></span> 
     <span class="token attr-name">sizes</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px<span class="token punctuation">"</span></span> 
     <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Responsive image<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>This ensures that smaller images are loaded on mobile devices while higher-resolution images are delivered to larger screens, significantly improving performance.</p>
<h2>The Use of JavaScript in Responsive Design</h2>
<p>While CSS is the foundation of responsive design, JavaScript can improve responsiveness, particularly in terms of interactivity. JavaScript allows developers to dynamically adapt content based on user interactions or changes in viewport size.</p>
<p>For example, JavaScript can be utilized to:</p>
<ul>
<li>Lazy-load images: This ensures that images only load when they appear in the viewport.</li>
<li>Dynamically modify font sizes: Text size is tailored to the current screen width.</li>
<li>Trigger animations are animations that adapt to varied device capabilities or screen sizes.</li>
</ul>
<h2>Accessibility is a critical component of responsiveness.</h2>
<p>Responsive web design is more than simply aesthetics and performance; it's also about accessibility. It is critical to ensure that your website is accessible to all visitors, including those with impairments. Techniques such as responsive font, scalable navigation, and ensuring that touch targets are properly scaled can significantly improve the user experience for users who use screen readers or assistive technology.</p>
<h2>Conclusion</h2>
<p>Responsive web design has advanced beyond the use of media queries. By incorporating fluid design, new CSS units, Flexbox, Grid, and JavaScript advancements, developers can create websites that are really flexible to any device or screen size. These strategies not only help to future-proof your designs, but they also increase accessibility and performance, resulting in a more seamless and engaging user experience.</p>
<blockquote>
<p>"True responsiveness lies in flexibility, not just in pixels, but in the ability to adapt to every user, on every device." - Burhanuddin Mulla Hamzabhai</p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Breaking a String into Multiple Lines Without Word Splits]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/breaking-a-string-into-multiple-lines-without-word-splits</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/breaking-a-string-into-multiple-lines-without-word-splits</guid>
            <pubDate>Thu, 22 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Efficiently Splitting Strings by Word Boundaries in TypeScript</p>
<h2>Problem</h2>
<p>Given a string s and an integer k, break up the string into multiple lines such that each line has a length of k or less. You must break it up so that words don’t break across lines. Each line has to have the maximum possible amount of words. If there’s no way to break the text up, then return null.</p>
<p>You can assume that there are no spaces at the ends of the string and that there is exactly one space between each word.</p>
<p>For example, given the string “the quick brown fox jumps over the lazy dog” and k = 10, you should return: [“the quick”, “brown fox”, “jumps over”, “the lazy”, “dog”]. No string in the list has a length of more than 10.</p>
<p>When working with strings, especially when formatting text, one common problem is ensuring that words do not split across lines. This can be particularly tricky when you have constraints on the maximum length of each line. In this solution, we will explore how to solve this problem efficiently in TypeScript.</p>
<h2>Problem Explanation</h2>
<p>You are given a string s and an integer k. The task is to break up the string into multiple lines such that:</p>
<ol>
<li>Each line has a length of k or less.</li>
<li>Words should not break across lines.</li>
<li>Each line should contain the maximum possible number of words.</li>
</ol>
<p>If it’s impossible to break the string as described, the function should return null.</p>
<p><strong>Example</strong></p>
<p>Given the string "the quick brown fox jumps over the lazy dog" and k = 10, the output should be:</p>
<pre><code>["the quick", "brown fox", "jumps over", "the lazy", "dog"]
</code></pre>
<h2>Step-by-Step Solution</h2>
<p><strong>Step 1: Understand the Constraints</strong></p>
<p>We need to ensure that each line we generate is within the length k, and words should not be split across lines. If a single word exceeds k, it's impossible to split the string as required.</p>
<p><strong>Step 2: Split the String into Words</strong></p>
<p>We will first split the string s into an array of words. This allows us to handle each word individually and decide where to place line breaks.</p>
<p><strong>Step 3: Accumulate Words into Lines</strong></p>
<p>We’ll iterate through the words, adding them to a line until adding another word would exceed k characters. Once a line is full, we'll start a new line.</p>
<p><strong>Step 4: Handle Edge Cases</strong></p>
<p>If any single word exceeds the length k, we'll return null.</p>
<h2>TypeScript Implementation</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">breakString</span><span class="token punctuation">(</span>s<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span> k<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword null nil">null</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> words <span class="token operator">=</span> s<span class="token punctuation">.</span><span class="token method function property-access">split</span><span class="token punctuation">(</span><span class="token string">" "</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> lines<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">let</span> currentLine <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>

    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> word <span class="token keyword">of</span> words<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// If a word is longer than k, return null</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>word<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">&gt;</span> k<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">return</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">// Check if adding the word exceeds the line length</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>currentLine<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">+</span> word<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">+</span> <span class="token punctuation">(</span>currentLine <span class="token operator">?</span> <span class="token number">1</span> <span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">&lt;=</span> k<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            currentLine <span class="token operator">+=</span> <span class="token punctuation">(</span>currentLine <span class="token operator">?</span> <span class="token string">" "</span> <span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token operator">+</span> word<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
            <span class="token comment">// Push the current line to the result and start a new line</span>
            lines<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span>currentLine<span class="token punctuation">)</span><span class="token punctuation">;</span>
            currentLine <span class="token operator">=</span> word<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Add the last line to the result</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>currentLine<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        lines<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span>currentLine<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> lines<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation</h2>
<ol>
<li><strong>Splitting the String:</strong> We first split the string s by spaces to get an array of words.</li>
<li><strong>Checking Word Length:</strong> For each word, if it exceeds the allowed length k, we return null.</li>
<li><strong>Building Lines:</strong> We attempt to build lines by adding words to the currentLine until it cannot fit more without exceeding the length k. If it does, we save the currentLine and start a new one.</li>
<li><strong>Final Step:</strong> The last accumulated line is added to the lines array.</li>
</ol>
<h2>Alternative Solutions and Considerations</h2>
<ul>
<li><strong>Greedy Approach:</strong> This approach is greedy, ensuring that each line is filled as much as possible. However, for some special cases, this might not yield the optimal arrangement.</li>
<li><strong>Dynamic Programming:</strong> A more complex solution might involve dynamic programming to find an optimal arrangement of words. However, for most cases, the above greedy approach is efficient and straightforward.</li>
</ul>
<h2>Conclusion</h2>
<p>This TypeScript solution efficiently breaks a string into multiple lines, ensuring that no words are split and each line is as full as possible within the given constraints. By carefully handling edge cases, such as words that are too long to fit within the limit, we ensure robustness in the solution.</p>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h2>Burhanuddin’s Code Compendium</h2>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>
<hr>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Check If One String Can Be Rotated Into Another Using TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/can-one-string-be-rotated-into-another</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/can-one-string-be-rotated-into-another</guid>
            <pubDate>Thu, 19 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Efficiently Check If One String Is a Shifted Version of Another</p>
<p><a href="https://medium.com/burhanuddins-code-compendium/can-one-string-be-rotated-into-another-2df4be9d53d1?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*pepQ8Ngepphdo6e6a1_lAg.png" alt=""></a></p>
<h2>Problem</h2>
<p>Given two strings A and B, return whether or not A can be shifted some number of times to get B.</p>
<p>For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, return false.</p>
<h2>Problem Breakdown</h2>
<p>We are given two strings A and B, and we need to check if A can be shifted (rotated) a certain number of times to get B.</p>
<p><strong>Example</strong></p>
<ul>
<li><code>A = “abcde”</code> and <code>B = “cdeab”</code> → return true because "abcde" can be shifted to form "cdeab".</li>
<li><code>A = “abc”</code> and <code>B = “acb”</code> → return false because no shift will make "abc" become "acb".</li>
</ul>
<h2>Approach</h2>
<p><strong>Length Check:</strong> First, if the lengths of A and B are different, it’s impossible for one string to be a shifted version of the other.</p>
<p><strong>String Rotation Insight:</strong> If we concatenate A with itself (i.e., A + A), all possible rotations of A will be present as a substring within this new string. For example:</p>
<ul>
<li><code>A = “abcde”</code></li>
<li><code>A + A = “abcdeabcde”</code> The string “cdeab” will be a substring of “abcdeabcde”.</li>
</ul>
<p><strong>Solution:</strong> If B is a substring of A + A, then B is a rotation of A.</p>
<h2>Code Implementation</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">canBeShifted</span><span class="token punctuation">(</span><span class="token constant">A</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token constant">B</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">boolean</span> <span class="token punctuation">{</span>
    <span class="token comment">// Check if the lengths of A and B are different</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token constant">A</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">!==</span> <span class="token constant">B</span><span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Concatenate A with itself</span>
    <span class="token keyword">const</span> doubleA <span class="token operator">=</span> <span class="token constant">A</span> <span class="token operator">+</span> <span class="token constant">A</span><span class="token punctuation">;</span>

    <span class="token comment">// Check if B is a substring of doubleA</span>
    <span class="token keyword control-flow">return</span> doubleA<span class="token punctuation">.</span><span class="token method function property-access">includes</span><span class="token punctuation">(</span><span class="token constant">B</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation:</h2>
<p><strong>Length Check:</strong> If A and B don’t have the same length, return false immediately because it’s impossible for A to be shifted to form B.</p>
<p><strong>Concatenation:</strong> Concatenate A with itself, resulting in a string that contains all possible rotations of A.</p>
<p><strong>Substring Check:</strong> If B is found within the concatenated string, A can be shifted to form B, so return true. Otherwise, return false.</p>
<h2>Example Walkthrough:</h2>
<p>Input: <code>A = “abcde”</code>, <code>B = “cdeab”</code></p>
<ul>
<li><code>doubleA = "abcdeabcde"</code></li>
<li>Check if “cdeab” is a substring of “abcdeabcde” → Yes → return true.</li>
</ul>
<p><strong>Input:</strong> <code>A = “abc”</code>, <code>B = “acb”</code></p>
<ul>
<li><code>doubleA = "abcabc"</code></li>
<li>Check if “acb” is a substring of “abcabc” → No → return false.</li>
</ul>
<h2>Time Complexity:</h2>
<p><strong>Time Complexity:</strong> O(n) where n is the length of string A (or B), because the most time-consuming operation is checking for the presence of B as a substring of A + A.
<strong>Space Complexity:</strong> O(n) due to the concatenation of A with itself.</p>
<h2>Alternative Approach:</h2>
<p>You could manually perform rotations and check each one, but this approach would be less efficient (O(n²) time complexity) than the string concatenation method.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Counting Attacking Bishop Pairs on a Chessboard with TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/counting-attacking-bishop-pairs-on-a-chessboard</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/counting-attacking-bishop-pairs-on-a-chessboard</guid>
            <pubDate>Thu, 01 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Efficiently Determine Attacking Bishop Pairs Using Diagonal Properties</p>
<p>In this article, we will solve a classic chess problem involving bishops and their attacking patterns on a special M by M chessboard. We’ll write an efficient TypeScript function to count the number of pairs of bishops that can attack each other.</p>
<h2>Problem</h2>
<p>On our special chessboard, two bishops attack each other if they share the same diagonal. This includes bishops that have another bishop located between them, i.e. bishops can attack through pieces.</p>
<p>You are given N bishops, represented as (row, column) tuples on a M by M chessboard. Write a function to count the number of pairs of bishops that attack each other. The ordering of the pair doesn’t matter: (1, 2) is considered the same as (2, 1).</p>
<p>For example, given M = 5 and the list of bishops:</p>
<ul>
<li>(0, 0)</li>
<li>(1, 2)</li>
<li>(2, 2)</li>
<li>(4, 0)</li>
</ul>
<p>The board would look like this:</p>
<pre><code>[b 0 0 0 0]
[0 0 b 0 0]
[0 0 b 0 0]
[0 0 0 0 0]
[b 0 0 0 0]
</code></pre>
<p>You should return 2, since bishops 1 and 3 attack each other, as well as bishops 3 and 4.</p>
<h2>Problem Description</h2>
<p>Given N bishops represented as (row, column) tuples on an M by M chessboard, two bishops attack each other if they share the same diagonal. This includes bishops that have another bishop located between them. We need to count the number of pairs of bishops that attack each other.</p>
<h2>Understanding Bishop Movement</h2>
<p>Bishops move diagonally, and there are two types of diagonals:</p>
<ul>
<li><strong>Primary Diagonal:</strong> From top-left to bottom-right, represented by cells where the difference between the row and column indices is constant (i - j).</li>
<li><strong>Secondary Diagonal:</strong> From top-right to bottom-left, represented by cells where the sum of the row and column indices is constant (i + j).</li>
</ul>
<h2>Approach</h2>
<p>To efficiently count the attacking pairs:</p>
<ol>
<li>Use dictionaries to keep track of the number of bishops on each diagonal.</li>
<li>For each diagonal, if there are n bishops, the number of attacking pairs is given by the combination formula n * (n - 1) / 2.</li>
</ol>
<h2>TypeScript Implementation</h2>
<p>Here’s the implementation:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">type</span> <span class="token class-name"><span class="token maybe-class-name">Position</span></span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token builtin">number</span><span class="token punctuation">,</span> <span class="token builtin">number</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">countAttackingPairs</span><span class="token punctuation">(</span><span class="token constant">M</span><span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> bishops<span class="token operator">:</span> <span class="token maybe-class-name">Position</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> primaryDiagonals<span class="token operator">:</span> <span class="token known-class-name class-name">Map</span><span class="token operator">&lt;</span><span class="token builtin">number</span><span class="token punctuation">,</span> <span class="token builtin">number</span><span class="token operator">&gt;</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Map</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> secondaryDiagonals<span class="token operator">:</span> <span class="token known-class-name class-name">Map</span><span class="token operator">&lt;</span><span class="token builtin">number</span><span class="token punctuation">,</span> <span class="token builtin">number</span><span class="token operator">&gt;</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Map</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// Populate the maps with counts of bishops on each diagonal</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token punctuation">[</span>row<span class="token punctuation">,</span> col<span class="token punctuation">]</span> <span class="token keyword">of</span> bishops<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">const</span> primaryDiag <span class="token operator">=</span> row <span class="token operator">-</span> col<span class="token punctuation">;</span>
        <span class="token keyword">const</span> secondaryDiag <span class="token operator">=</span> row <span class="token operator">+</span> col<span class="token punctuation">;</span>

        primaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span>primaryDiag<span class="token punctuation">,</span> <span class="token punctuation">(</span>primaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span>primaryDiag<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        secondaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span>secondaryDiag<span class="token punctuation">,</span> <span class="token punctuation">(</span>secondaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span>secondaryDiag<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">let</span> attackingPairs <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">// Calculate pairs for primary diagonals</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">const</span> count <span class="token keyword">of</span> primaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>count <span class="token operator">&gt;</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            attackingPairs <span class="token operator">+=</span> <span class="token punctuation">(</span>count <span class="token operator">*</span> <span class="token punctuation">(</span>count <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Calculate pairs for secondary diagonals</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">const</span> count <span class="token keyword">of</span> secondaryDiagonals<span class="token punctuation">.</span><span class="token method function property-access">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>count <span class="token operator">&gt;</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            attackingPairs <span class="token operator">+=</span> <span class="token punctuation">(</span>count <span class="token operator">*</span> <span class="token punctuation">(</span>count <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> attackingPairs<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// Example usage:</span>
<span class="token keyword">const</span> <span class="token constant">M</span> <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> bishops<span class="token operator">:</span> <span class="token maybe-class-name">Position</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token function">countAttackingPairs</span><span class="token punctuation">(</span><span class="token constant">M</span><span class="token punctuation">,</span> bishops<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Output: 2</span>
</code></pre>
<h2>Explanation</h2>
<p><strong>Data Collection:</strong></p>
<ul>
<li>We iterate over each bishop and update two maps: primaryDiagonals and secondaryDiagonals. The keys are the diagonal identifiers, and the values are the counts of bishops on those diagonals.</li>
</ul>
<p><strong>Counting Attack Pairs:</strong></p>
<ul>
<li>For each entry in both maps, if the count of bishops on a diagonal is greater than 1, we calculate the number of attacking pairs using the combination formula n * (n - 1) / 2 and sum these values.</li>
</ul>
<h2>Alternative Solutions</h2>
<p><strong>Brute Force:</strong></p>
<ul>
<li>Iterate through all pairs of bishops and check if they share the same diagonal. This approach has a time complexity of O(N²), where N is the number of bishops, and is less efficient for larger inputs.</li>
</ul>
<p><strong>Optimized Approach:</strong></p>
<ul>
<li>The provided diagonal counting method has a time complexity of O(N), making it suitable for larger inputs.</li>
</ul>
<h2>Conclusion</h2>
<p>The solution provided is efficient and leverages the properties of diagonals to count the attacking pairs of bishops effectively. This approach ensures we handle larger inputs gracefully and with optimal performance.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>
<hr>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Detect Arbitrage in Currency Exchange with Bellman-Ford Algorithm]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/detecting-arbitrage-in-currency-exchange-rates-using-graph-theory-and-bellman-ford-algorithm</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/detecting-arbitrage-in-currency-exchange-rates-using-graph-theory-and-bellman-ford-algorithm</guid>
            <pubDate>Thu, 26 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-compendium/detecting-arbitrage-in-currency-exchange-rates-using-graph-theory-and-bellman-ford-algorithm-929e7ef2fb2a?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*lUuchRMiOxwATWOkqqsKfg.png" alt=""></a></p>
<p>How to Identify Arbitrage Opportunities in Currency Markets with Efficient Graph-Based Solutions</p>
<h2>Problem</h2>
<p>Suppose you are given a table of currency exchange rates, represented as a 2D array. Determine whether there is a possible arbitrage: that is, whether there is some sequence of trades you can make, starting with some amount A of any currency, so that you can end up with some amount greater than A of that currency. There are no transaction costs and you can trade fractional quantities.</p>
<h2>Problem Explanation</h2>
<p>You are given a 2D array representing currency exchange rates between different currencies. Each element of the array, rates[i][j], represents the exchange rate from currency i to currency j. The goal is to determine if there is an arbitrage opportunity, meaning if you can start with an amount of currency, perform a series of trades, and end up with more of that currency than you started with.</p>
<h2>Approach</h2>
<p>This problem can be solved using graph theory, specifically Bellman-Ford algorithm. Here's how it works:</p>
<h2>Graph Representation:</h2>
<ul>
<li>
<p>Treat each currency as a node in a graph.</p>
</li>
<li>
<p>Each exchange rate between two currencies is treated as a directed edge between two nodes.</p>
</li>
</ul>
<h2>Edge Weights Transformation:</h2>
<ul>
<li>The exchange rates are multiplicative. To use Bellman-Ford (which operates on sums), we need to transform the weights.</li>
<li>Use logarithms to convert the problem to an additive form:</li>
</ul>
<pre class="language-typescript"><code class="language-typescript"><span class="token function">weight</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span>j<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token function">−log⁡</span><span class="token punctuation">(</span>rate<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre>
<p>By using logarithms and negating, we turn the problem into detecting a negative weight cycle in a graph. A negative weight cycle corresponds to an arbitrage opportunity.</p>
<h2>Cycle Detection:</h2>
<p>If we find a negative weight cycle in this transformed graph, it means there is an arbitrage opportunity.
The Bellman-Ford algorithm can detect negative weight cycles in a graph.</p>
<p>Solution Code:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">detectArbitrage</span><span class="token punctuation">(</span>rates<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">boolean</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> n <span class="token operator">=</span> rates<span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">;</span>

    <span class="token comment">// Convert rates to log space: log(-rate)</span>
    <span class="token keyword">const</span> logRates<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token known-class-name class-name">Array</span><span class="token punctuation">.</span><span class="token keyword module">from</span><span class="token punctuation">(</span><span class="token punctuation">{</span> length<span class="token operator">:</span> n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=&gt;</span> <span class="token known-class-name class-name">Array</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">fill</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            logRates<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token operator">-</span><span class="token known-class-name class-name">Math</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>rates<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Run Bellman-Ford to detect negative cycle</span>
    <span class="token keyword">const</span> distances <span class="token operator">=</span> <span class="token known-class-name class-name">Array</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">fill</span><span class="token punctuation">(</span><span class="token number">Infinity</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">// We can start from any node, here we use node 0</span>
    distances<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> k <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> k <span class="token operator">&lt;</span> n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span> k<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>distances<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">+</span> logRates<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">&lt;</span> distances<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    distances<span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">=</span> distances<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">+</span> logRates<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Check for negative weight cycles</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> n<span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>distances<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">+</span> logRates<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">&lt;</span> distances<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword control-flow">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token comment">// Arbitrage detected</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token comment">// No arbitrage found</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation of&nbsp;Code</h2>
<h2>Convert Rates to Logarithmic Space:</h2>
<p>We first convert the rates to a logarithmic space using -Math.log(rates[i][j]), which allows us to transform the problem from a multiplicative relationship into an additive one.</p>
<h2>Bellman-Ford Algorithm:</h2>
<p>We initialize the distances from the start node (chosen arbitrarily as node 0) to all other nodes as infinity (Infinity), except for the start node itself which is 0.
The Bellman-Ford algorithm then runs for n-1 iterations, where n is the number of currencies. In each iteration, we relax all edges and update the distances.</p>
<h2>Negative Cycle Detection:</h2>
<p>After n-1 iterations, we perform one more iteration to check if we can still relax any edge. If so, it indicates the presence of a negative weight cycle, which corresponds to an arbitrage opportunity.</p>
<h2>Time Complexity</h2>
<ul>
<li>Time Complexity: <code>O(n^3)</code> where n is the number of currencies. This is because we perform n-1 iterations over all pairs of nodes, and for each pair, we update the distances.</li>
<li>Space Complexity: <code>O(n^2)</code> because we store the logRates matrix and the distance array.</li>
</ul>
<h2>Conclusion</h2>
<p>The above solution detects whether an arbitrage opportunity exists using the Bellman-Ford algorithm. If a negative weight cycle is found, it indicates the presence of arbitrage. The transformation to logarithmic space allows us to handle the multiplicative nature of exchange rates.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>
<hr>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Efficient Solution to Sum of Squares Problem in TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/efficient-solution-to-sum-of-squares-problem</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/efficient-solution-to-sum-of-squares-problem</guid>
            <pubDate>Thu, 08 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Optimizing Sum of Squares for a Given Positive Integer</p>
<h2>Problem</h2>
<p>Given a positive integer n, find the smallest number of squared integers which sum to n.</p>
<p>For example, given n = 13, return 2 since 13 = 32 + 22 = 9 + 4.</p>
<p>Given n = 27, return 3 since 27 = 32 + 32 + 32 = 9 + 9 + 9.</p>
<h2>Problem Explanation</h2>
<p>Given a positive integer n, our task is to find the smallest number of squared integers that sum up to n. This problem can be efficiently solved using a dynamic programming approach. We will build up the solution by solving smaller subproblems and using their solutions to construct the solution for larger problems.</p>
<h2>Examples</h2>
<ul>
<li>For n = 13, the smallest number of squared integers is 2 (since 13 = 3² + 2² = 9 + 4).</li>
<li>For n = 27, the smallest number of squared integers is 3 (since 27 = 3² + 3² + 3² = 9 + 9 + 9).</li>
</ul>
<h2>Step-by-Step Solution</h2>
<p><strong>Understanding the Problem</strong> :</p>
<ul>
<li>We need to find the minimum number of perfect square numbers (like 1, 4, 9, etc.) that sum up to the given integer n.</li>
</ul>
<p><strong>Dynamic Programming Approach</strong> :</p>
<ul>
<li>We will use a dynamic programming array dp where dp[i] represents the smallest number of squared integers that sum up to i.</li>
<li>Initialize dp[0] to 0 since 0 can be represented by 0 numbers.</li>
<li>For each number from 1 to n, we will find the minimum number of squared integers that sum to that number by iterating over all possible squared integers that are less than or equal to the current number.</li>
</ul>
<p><strong>Algorithm</strong> :</p>
<ul>
<li>Initialize an array dp of size n + 1 with all values set to infinity, except dp[0] which is 0.</li>
<li>For each number <code>i</code> from 1 to <code>n</code>, iterate through all possible squared integers <code>j^2</code> (where <code>j^2 &lt;= i</code>) and update <code>dp[i]</code> as <code>dp[i] = min(dp[i], dp[i - j^2] + 1)</code>.</li>
</ul>
<h2><strong>TypeScript Implementation</strong> :</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">minSquares</span><span class="token punctuation">(</span>n<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> dp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Array</span></span><span class="token punctuation">(</span>n <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">fill</span><span class="token punctuation">(</span><span class="token number">Infinity</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    dp<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> n<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> j <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> j <span class="token operator">*</span> j <span class="token operator">&lt;=</span> i<span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            dp<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token known-class-name class-name">Math</span><span class="token punctuation">.</span><span class="token method function property-access">min</span><span class="token punctuation">(</span>dp<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> dp<span class="token punctuation">[</span>i <span class="token operator">-</span> j <span class="token operator">*</span> j<span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> dp<span class="token punctuation">[</span>n<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// Example usage:</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token function">minSquares</span><span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Output: 2</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token function">minSquares</span><span class="token punctuation">(</span><span class="token number">27</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Output: 3</span>
</code></pre>
<h2>Explanation of the Code:</h2>
<p><strong>Initialization</strong> :</p>
<ul>
<li>We create an array dp of length n + 1 and initialize all values to infinity. The value at dp[0] is set to 0 because zero squared integers sum to 0.</li>
</ul>
<p><strong>Dynamic Programming Loop</strong> :</p>
<ul>
<li>For each number i from 1 to n, we iterate through all perfect squares j^2 that are less than or equal to i.</li>
<li>For each perfect square j^2, we update dp[i] with the minimum value between dp[i] and dp[i - j^2] + 1.</li>
<li>The dp[i - j^2] + 1 represents the number of squared integers needed to sum to i, considering one more square j^2.</li>
</ul>
<h2>Alternative Solutions</h2>
<p><strong>Breadth-First Search (BFS)</strong>:</p>
<ul>
<li>Another approach is to use BFS where each node in the search tree represents a remaining value to be decomposed into squares. This method can be more intuitive but might not be as efficient as the dynamic programming approach.</li>
</ul>
<h2>Conclusion</h2>
<p>Using dynamic programming provides an efficient way to solve the problem of finding the smallest number of squared integers that sum up to a given number n. The algorithm runs in O(n√n) time, making it suitable for large values of n.</p>
<blockquote>
<p>“Optimizing code is like solving a puzzle — each piece you place perfectly brings you closer to the complete picture.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>
<p>This solution provides a comprehensive approach to understanding and implementing the dynamic programming technique for this problem, ensuring an efficient and effective solution.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>
<hr>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Efficient Solution to Sum of Squares Problem in TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/efficiently-computing-the-running-median-in-typeScript-using-heaps</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/efficiently-computing-the-running-median-in-typeScript-using-heaps</guid>
            <pubDate>Thu, 03 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-compendium/efficiently-computing-the-running-median-in-typescript-using-heaps-b0d7d688173a?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*LPfQTKlSVH0O-GR4jHyD8Q.png" alt=""></a></p>
<p>A Step-by-Step Guide to Calculating the Running Median of a Number Stream with Optimized Algorithms</p>
<h2>Problem</h2>
<p>Compute the running median of a sequence of numbers. That is, given a stream of numbers, print out the median of the list so far on each new element.</p>
<p>Recall that the median of an even-numbered list is the average of the two middle numbers.</p>
<p>For example, given the sequence [2, 1, 5, 7, 2, 0, 5], your algorithm should print out:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token number">2</span>
<span class="token number">1.5</span>
<span class="token number">2</span>
<span class="token number">3.5</span>
<span class="token number">2</span>
<span class="token number">2</span>
<span class="token number">2</span>
</code></pre>
<h2>Problem Breakdown</h2>
<h2>Median Definition:</h2>
<p>For an odd-sized list, the median is the middle element.</p>
<p>For an even-sized list, the median is the average of the two middle elements.</p>
<h2>Efficient Calculation:</h2>
<p>We need to efficiently insert numbers into the list and then quickly find the median after each insertion.</p>
<p>Maintaining a sorted list would work, but re-sorting the list after each insertion is costly (O(n log n)).</p>
<p>A more efficient way to handle this is by using two heaps (min-heap and max-heap):</p>
<ul>
<li>Max-heap stores the smaller half of the numbers.</li>
<li>Min-heap stores the larger half of the numbers.</li>
</ul>
<h2>Algorithm Explanation:</h2>
<p>At each step, we:</p>
<ol>
<li>Insert the new number into one of the heaps.</li>
<li>Ensure the heaps are balanced, i.e., the number of elements in the max-heap and min-heap differs by at most 1.</li>
<li>Calculate the median:</li>
</ol>
<ul>
<li>If both heaps have the same size, the median is the average of the two roots (top elements) of the heaps.</li>
<li>If the max-heap has one more element than the min-heap, the median is the root of the max-heap.</li>
</ul>
<h2>Solution in TypeScript:</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">RunningMedian</span></span> <span class="token punctuation">{</span>
  <span class="token keyword">private</span> minHeap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// larger half (min-heap)</span>
  <span class="token keyword">private</span> maxHeap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// smaller half (max-heap, represented as a max-heap using negated values)</span>

  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

  <span class="token comment">// Helper to insert into heap (push and reheapify)</span>
  <span class="token keyword">private</span> <span class="token function">insertHeap</span><span class="token punctuation">(</span>heap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> value<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> isMinHeap<span class="token operator">:</span> <span class="token builtin">boolean</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    heap<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">heapifyUp</span><span class="token punctuation">(</span>heap<span class="token punctuation">,</span> heap<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">,</span> isMinHeap<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// Helper to remove the root element from a heap (pop and reheapify)</span>
  <span class="token keyword">private</span> <span class="token function">removeHeapRoot</span><span class="token punctuation">(</span>heap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> isMinHeap<span class="token operator">:</span> <span class="token builtin">boolean</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> root <span class="token operator">=</span> heap<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> last <span class="token operator">=</span> heap<span class="token punctuation">.</span><span class="token method function property-access">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>heap<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> last <span class="token operator">!==</span> <span class="token keyword nil">undefined</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      heap<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> last<span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">heapifyDown</span><span class="token punctuation">(</span>heap<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> isMinHeap<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword control-flow">return</span> root<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// Heapify up: restore the heap property after insertion</span>
  <span class="token keyword">private</span> <span class="token function">heapifyUp</span><span class="token punctuation">(</span>heap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> index<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> isMinHeap<span class="token operator">:</span> <span class="token builtin">boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">while</span> <span class="token punctuation">(</span>index <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> parentIndex <span class="token operator">=</span> <span class="token known-class-name class-name">Math</span><span class="token punctuation">.</span><span class="token method function property-access">floor</span><span class="token punctuation">(</span><span class="token punctuation">(</span>index <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>isMinHeap <span class="token operator">?</span> heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span> <span class="token operator">&lt;</span> heap<span class="token punctuation">[</span>parentIndex<span class="token punctuation">]</span> <span class="token operator">:</span> heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span> <span class="token operator">&gt;</span> heap<span class="token punctuation">[</span>parentIndex<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">[</span>heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">,</span> heap<span class="token punctuation">[</span>parentIndex<span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>heap<span class="token punctuation">[</span>parentIndex<span class="token punctuation">]</span><span class="token punctuation">,</span> heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        index <span class="token operator">=</span> parentIndex<span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">break</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// Heapify down: restore the heap property after removal</span>
  <span class="token keyword">private</span> <span class="token function">heapifyDown</span><span class="token punctuation">(</span>heap<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> index<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> isMinHeap<span class="token operator">:</span> <span class="token builtin">boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> length <span class="token operator">=</span> heap<span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">;</span>
    <span class="token keyword control-flow">while</span> <span class="token punctuation">(</span>index <span class="token operator">&lt;</span> length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> leftChild <span class="token operator">=</span> <span class="token number">2</span> <span class="token operator">*</span> index <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
      <span class="token keyword">const</span> rightChild <span class="token operator">=</span> <span class="token number">2</span> <span class="token operator">*</span> index <span class="token operator">+</span> <span class="token number">2</span><span class="token punctuation">;</span>
      <span class="token keyword">let</span> target <span class="token operator">=</span> index<span class="token punctuation">;</span>

      <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>leftChild <span class="token operator">&lt;</span> length <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>isMinHeap <span class="token operator">?</span> heap<span class="token punctuation">[</span>leftChild<span class="token punctuation">]</span> <span class="token operator">&lt;</span> heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span> <span class="token operator">:</span> heap<span class="token punctuation">[</span>leftChild<span class="token punctuation">]</span> <span class="token operator">&gt;</span> heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        target <span class="token operator">=</span> leftChild<span class="token punctuation">;</span>
      <span class="token punctuation">}</span>

      <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>rightChild <span class="token operator">&lt;</span> length <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>isMinHeap <span class="token operator">?</span> heap<span class="token punctuation">[</span>rightChild<span class="token punctuation">]</span> <span class="token operator">&lt;</span> heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span> <span class="token operator">:</span> heap<span class="token punctuation">[</span>rightChild<span class="token punctuation">]</span> <span class="token operator">&gt;</span> heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        target <span class="token operator">=</span> rightChild<span class="token punctuation">;</span>
      <span class="token punctuation">}</span>

      <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>target <span class="token operator">!==</span> index<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">[</span>heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">,</span> heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>heap<span class="token punctuation">[</span>target<span class="token punctuation">]</span><span class="token punctuation">,</span> heap<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        index <span class="token operator">=</span> target<span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">break</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token function">addNumber</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{</span>
    <span class="token comment">// Step 1: Add number to maxHeap or minHeap</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token operator">||</span> num <span class="token operator">&lt;=</span> <span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">insertHeap</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">,</span> <span class="token operator">-</span>num<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Negative to use max-heap property</span>
    <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">insertHeap</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">,</span> num<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Normal min-heap</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Step 2: Balance heaps (ensure maxHeap has at most 1 more element than minHeap)</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> maxRoot <span class="token operator">=</span> <span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">removeHeapRoot</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">insertHeap</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">,</span> maxRoot<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> minRoot <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">removeHeapRoot</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">insertHeap</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">,</span> <span class="token operator">-</span>minRoot<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">public</span> <span class="token function">getMedian</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword control-flow">return</span> <span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
      <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span><span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">maxHeap</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">minHeap</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// Example usage:</span>
<span class="token keyword">const</span> sequence <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> runningMedian <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token maybe-class-name">RunningMedian</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

sequence<span class="token punctuation">.</span><span class="token method function property-access">forEach</span><span class="token punctuation">(</span>num <span class="token arrow operator">=&gt;</span> <span class="token punctuation">{</span>
  runningMedian<span class="token punctuation">.</span><span class="token method function property-access">addNumber</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>runningMedian<span class="token punctuation">.</span><span class="token method function property-access">getMedian</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h2>Explanation:</h2>
<h2>Heaps:</h2>
<ul>
<li>minHeap: A min-heap that holds the larger half of the numbers.</li>
<li>maxHeap: A max-heap (implemented using negated values) that holds the smaller half.</li>
</ul>
<h2>Balancing Heaps:</h2>
<p>After inserting a number, we balance the heaps by making sure that the max-heap has at most one more element than the min-heap.</p>
<h2>Median Calculation:</h2>
<ul>
<li>If the max-heap contains more elements, the median is the root of the max-heap.</li>
<li>If both heaps have an equal number of elements, the median is the average of the two roots.</li>
</ul>
<h2>Time Complexity:</h2>
<ul>
<li>Inserting into the heap takes O(log n) due to heap properties.</li>
<li>Finding the median is O(1) since we just need to access the root(s) of the heaps.</li>
<li>Thus, the overall time complexity per insertion is O(log n).</li>
</ul>
<h2>Alternative Solutions:</h2>
<p>A brute force approach could sort the array after every insertion, but that would result in O(n log n) per insertion. The heap-based solution is more efficient for large input sizes.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Efficiently Tracking Last N Orders Using a Circular Buffer in TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/efficiently-tracking-last-n-orders-using-a-circular-buffer</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/efficiently-tracking-last-n-orders-using-a-circular-buffer</guid>
            <pubDate>Thu, 12 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>A Step-by-Step Guide to Implementing a Space and Time Efficient Log for E-commerce Orders</p>
<p><a href="https://medium.com/burhanuddins-code-compendium/efficiently-tracking-last-n-orders-using-a-circular-buffer-in-typescript-a98aa427a811?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*z_Dm1QKt2iJdOAN7fh0b2A.png" alt=""></a></p>
<h2>Problem</h2>
<p>You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this, with the following API:</p>
<ul>
<li>record(order_id): adds the order_id to the log</li>
<li>get_last(i): gets the ith last element from the log. i is guaranteed to be smaller than or equal to N.</li>
<li>You should be as efficient with time and space as possible.</li>
</ul>
<h2>Solution</h2>
<p>To solve this problem, we can use a circular buffer (or ring buffer). A circular buffer efficiently handles recording and retrieving the last N items, maintaining constant space and allowing for efficient updates. Let’s break down the approach:</p>
<h2>Approach:</h2>
<p><strong>Circular Buffer Concept:</strong></p>
<ul>
<li>The buffer will have a fixed size N, and it will "wrap around" when it reaches the end of the buffer.</li>
<li>We’ll maintain an array of size N, and a pointer (currentIndex) that keeps track of where the next order ID should be inserted.</li>
</ul>
<p><strong>Recording an order:</strong></p>
<ul>
<li>Every time we add an order ID, it will be inserted at the position currentIndex % N in the buffer, and the pointer currentIndex will increment.</li>
</ul>
<p><strong>Retrieving an order:</strong></p>
<ul>
<li>To get the ith last element, we’ll calculate the correct position in the buffer. The element at position (currentIndex - i) % N will give the ith last order.
This approach is space efficient, as we only store the last N order IDs, and it’s time efficient, with both record and get_last operations having constant time complexity, O(1).</li>
</ul>
<h2>Step-by-Step Solution:</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">OrderLog</span></span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> log<span class="token operator">:</span> <span class="token punctuation">(</span><span class="token builtin">number</span> <span class="token operator">|</span> <span class="token keyword null nil">null</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>  <span class="token comment">// Array to store the order IDs</span>
    <span class="token keyword">private</span> <span class="token constant">N</span><span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">;</span>  <span class="token comment">// Size of the buffer (the maximum number of last records to store)</span>
    <span class="token keyword">private</span> currentIndex<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">;</span>  <span class="token comment">// Index where the next order ID should be inserted</span>

    <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token constant">N</span><span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token constant">N</span> <span class="token operator">=</span> <span class="token constant">N</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">log</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Array</span></span><span class="token punctuation">(</span><span class="token constant">N</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">fill</span><span class="token punctuation">(</span><span class="token keyword null nil">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Initialize the buffer with null values</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">currentIndex</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>  <span class="token comment">// Start at the first position</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Adds an order ID to the log</span>
    <span class="token function">record</span><span class="token punctuation">(</span>order_id<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">log</span><span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">currentIndex</span> <span class="token operator">%</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token constant">N</span><span class="token punctuation">]</span> <span class="token operator">=</span> order_id<span class="token punctuation">;</span>  <span class="token comment">// Insert the order at the current index</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">currentIndex</span><span class="token operator">++</span><span class="token punctuation">;</span>  <span class="token comment">// Move the index forward</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// Gets the ith last order ID from the log</span>
    <span class="token function">get_last</span><span class="token punctuation">(</span>i<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> <span class="token keyword null nil">null</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>i <span class="token operator">&lt;</span> <span class="token number">1</span> <span class="token operator">||</span> i <span class="token operator">&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token constant">N</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">throw</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Error</span></span><span class="token punctuation">(</span><span class="token string">"Index out of bounds"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">const</span> index <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">currentIndex</span> <span class="token operator">-</span> i <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token constant">N</span><span class="token punctuation">)</span> <span class="token operator">%</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token constant">N</span><span class="token punctuation">;</span>  <span class="token comment">// Calculate the correct index</span>
        <span class="token keyword control-flow">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">log</span><span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">;</span>  <span class="token comment">// Return the ith last order ID</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation:</h2>
<ol>
<li>Constructor: Initializes the log with a size N. The log is an array filled with null to represent empty slots, and currentIndex starts at 0.</li>
<li>record(order_id): Adds the given order_id to the buffer at position currentIndex % N. After each insertion, currentIndex is incremented.</li>
<li>get_last(i): Retrieves the ith last element by calculating the correct index in the circular buffer. The formula (currentIndex - i + N) % N ensures that even if the index becomes negative (when currentIndex - i is less than 0), it wraps around to the correct position.</li>
</ol>
<h2>Time and Space Complexity:</h2>
<ul>
<li>Time Complexity: Both record and get_last operations are O(1), as array indexing and modulo operations are constant time.</li>
<li>Space Complexity: The space used is O(N), since we only maintain an array of size N.</li>
</ul>
<p><strong>Example Usage:</strong></p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">const</span> orderLog <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token maybe-class-name">OrderLog</span></span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// We will store the last 5 order IDs</span>

orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">101</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">102</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">103</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">104</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">105</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>orderLog<span class="token punctuation">.</span><span class="token method function property-access">get_last</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 105 (most recent)</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>orderLog<span class="token punctuation">.</span><span class="token method function property-access">get_last</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 103 (third last)</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>orderLog<span class="token punctuation">.</span><span class="token method function property-access">get_last</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 101 (fifth last)</span>

orderLog<span class="token punctuation">.</span><span class="token method function property-access">record</span><span class="token punctuation">(</span><span class="token number">106</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>orderLog<span class="token punctuation">.</span><span class="token method function property-access">get_last</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 106</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>orderLog<span class="token punctuation">.</span><span class="token method function property-access">get_last</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 102 (101 is overwritten)</span>
</code></pre>
<h2>Alternative Approaches:</h2>
<ul>
<li>Deque or Linked List: You could also use a doubly linked list or a deque for this problem. However, this would generally result in a more complex implementation and potentially higher memory overhead compared to the circular buffer.</li>
</ul>
<p>The circular buffer is the most space- and time-efficient solution for this scenario, meeting the requirement to efficiently manage the last N order IDs.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h2>Burhanuddin’s Code Compendium</h2>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Minimum Number of Swaps to Arrange Couples]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/minimum-number-of-swaps-to-arrange-couples</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/minimum-number-of-swaps-to-arrange-couples</guid>
            <pubDate>Thu, 10 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p><a href="https://medium.com/burhanuddins-code-compendium/minimum-number-of-swaps-to-arrange-couples-45cd5663c49a?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*mI6XfwuRu7smg7Q0hJEdSw.png" alt=""></a></p>
<p>We are given 2×N seats, where N couples are sitting in random order. Our task is to rearrange them so that each couple is sitting together. A couple is identified by having two consecutive seat positions. We need to determine the minimum number of swaps required to achieve this arrangement.</p>
<h2>Key Insights:</h2>
<ol>
<li>Pair Identification: Each individual has a unique identifier, but we can say that persons i and i+1 form a couple (or any unique pair). For instance, if persons are indexed from 0, then a couple could be (0,1),(2,3),…,(2×N−2,2×N−1).</li>
<li>Swaps: A swap can be considered as exchanging the positions of two people. The goal is to reduce the number of mismatched pairs in the least number of swaps.</li>
</ol>
<h2>Approach:</h2>
<p>This problem can be mapped as a minimum swap problem in a permutation. We’ll use greedy swaps to correct the position of each person to form couples side-by-side.</p>
<h2>Steps:</h2>
<h2>Create a mapping:</h2>
<p>We’ll create a map that links each person to their partner. For instance, if person 0 is the partner of person 1, and 2 is the partner of person 3, this will be used to easily identify the correct couple positions.</p>
<h2>Iterate through the row:</h2>
<p>For each couple, check if they are sitting together. If not, we will perform a swap with the person’s actual partner, using the mapping created.</p>
<h2>Count swaps:</h2>
<p>Each time we swap two persons to correct their position, we increment the count of swaps.</p>
<h2>Solution:</h2>
<p>Here’s the TypeScript implementation that solves the problem efficiently:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">minSwapsCouples</span><span class="token punctuation">(</span>row<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> n <span class="token operator">=</span> row<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> partner <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token known-class-name class-name">Map</span><span class="token operator">&lt;</span><span class="token builtin">number</span><span class="token punctuation">,</span> <span class="token builtin">number</span><span class="token operator">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">// Create mapping for each couple's position</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> row<span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        partner<span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span>row<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">let</span> swaps <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">// Loop through each couple position</span>
    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> n <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">;</span> i <span class="token operator">+=</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">const</span> firstPerson <span class="token operator">=</span> row<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> secondPerson <span class="token operator">=</span> row<span class="token punctuation">[</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> correctPartner <span class="token operator">=</span> firstPerson <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token operator">?</span> firstPerson <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">:</span> firstPerson <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span>

        <span class="token comment">// If the current person is not sitting with their partner, swap them</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>secondPerson <span class="token operator">!==</span> correctPartner<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            swaps<span class="token operator">++</span><span class="token punctuation">;</span>

            <span class="token comment">// Find the partner's current position</span>
            <span class="token keyword">const</span> partnerIndex <span class="token operator">=</span> partner<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span>correctPartner<span class="token punctuation">)</span><span class="token operator">!</span><span class="token punctuation">;</span>

            <span class="token comment">// Swap the second person with the correct partner</span>
            row<span class="token punctuation">[</span>partnerIndex<span class="token punctuation">]</span> <span class="token operator">=</span> secondPerson<span class="token punctuation">;</span>
            row<span class="token punctuation">[</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> correctPartner<span class="token punctuation">;</span>

            <span class="token comment">// Update the partner map after the swap</span>
            partner<span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span>secondPerson<span class="token punctuation">,</span> partnerIndex<span class="token punctuation">)</span><span class="token punctuation">;</span>
            partner<span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span>correctPartner<span class="token punctuation">,</span> i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> swaps<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation:</h2>
<ol>
<li>Mapping Partners: We create a partner map that stores each person’s current position. This helps us quickly find where a person’s partner is sitting.</li>
<li>Iterate in Pairs: We loop through the list in steps of two (since each person in the row should sit with their partner).</li>
<li>Check and Swap: For each pair, we check if the two people are already partners. If not, we swap the current person’s seat with their partner and update the map accordingly.</li>
<li>Counting Swaps: We count every swap performed.</li>
</ol>
<h2>Time Complexity:</h2>
<ul>
<li>Time Complexity: O(N) since we are making at most N swaps, where N is the number of couples. Creating and updating the map and performing swaps is also linear.</li>
<li>Space Complexity: O(N) due to the map storing the positions of each person.</li>
</ul>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">const</span> row <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token function">minSwapsCouples</span><span class="token punctuation">(</span>row<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Output: 1</span>
</code></pre>
<p>In the example above, we only need one swap to make sure persons 0 and 1 are together, and persons 2 and 3 are together.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Optimized Fibonacci Sequence in TypeScript with O(1) Space Complexity]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/optimized-fibonacci-sequence</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/optimized-fibonacci-sequence</guid>
            <pubDate>Thu, 15 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Efficiently Calculate the nth Fibonacci Number Using Constant Space</p>
<h2>Problem Overview: Fibonacci Sequence with O(1) Space Complexity</h2>
<p>The problem requires implementing the fib(n) function to return the nth number in the Fibonacci sequence using only O(1) space complexity.</p>
<h2>Fibonacci Sequence Recap:</h2>
<p>The Fibonacci sequence is defined as:</p>
<ul>
<li>F(0) = 0</li>
<li>F(1) = 1</li>
<li>F(n) = F(n−1) + F(n−2) for n ≥ 2</li>
</ul>
<p>Given that the Fibonacci sequence grows exponentially, the challenge lies in efficiently calculating F(n) without consuming extra space.</p>
<h2>Constraints:</h2>
<ul>
<li>We must achieve O(1) space complexity.</li>
<li>The time complexity should ideally be O(n).</li>
</ul>
<h2>Solution Approach:</h2>
<p>To achieve O(1) space, we can iteratively compute the Fibonacci numbers while only storing the last two computed values. This eliminates the need for storing the entire sequence.</p>
<h2>Steps:</h2>
<ol>
<li><strong>Base Cases</strong> : Directly return the value for n = 0 and n = 1.</li>
<li><strong>Iterative Calculation</strong> : Use a loop to calculate the nth Fibonacci number by updating the previous two values iteratively.</li>
</ol>
<h2>TypeScript Implementation:</h2>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">fib</span><span class="token punctuation">(</span>n<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>n <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token keyword control-flow">return</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token comment">// Base case F(0)</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>n <span class="token operator">===</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword control-flow">return</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// Base case F(1)</span>

    <span class="token keyword">let</span> prev2 <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token comment">// F(0)</span>
    <span class="token keyword">let</span> prev1 <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// F(1)</span>

    <span class="token keyword control-flow">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> n<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> current <span class="token operator">=</span> prev1 <span class="token operator">+</span> prev2<span class="token punctuation">;</span> <span class="token comment">// F(i) = F(i-1) + F(i-2)</span>
        prev2 <span class="token operator">=</span> prev1<span class="token punctuation">;</span> <span class="token comment">// Update F(i-2)</span>
        prev1 <span class="token operator">=</span> current<span class="token punctuation">;</span> <span class="token comment">// Update F(i-1)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword control-flow">return</span> prev1<span class="token punctuation">;</span> <span class="token comment">// Return the nth Fibonacci number</span>
<span class="token punctuation">}</span>
</code></pre>
<h2>Explanation:</h2>
<ul>
<li><strong>Base Cases</strong> : The function checks if <em>n</em> is 0 or 1 and returns the corresponding Fibonacci number immediately.</li>
<li><strong>Iterative Loop</strong> : Starting from 2 to <em>n</em>, the loop calculates the current Fibonacci number as the sum of the previous two numbers.</li>
<li><strong>Update</strong> : After calculating the current Fibonacci number, the previous two numbers are updated for the next iteration.</li>
<li><strong>O(1) Space</strong>: This approach only uses two variables, ensuring constant space usage.</li>
</ul>
<h2>Alternative Solutions:</h2>
<ul>
<li><strong>Matrix Exponentiation</strong> : This method can compute Fibonacci in O(log n) time but is more complex and typically requires more space.</li>
<li><strong>Binet’s Formula</strong> : Using a direct formula involving the golden ratio. While it offers O(1) space, it suffers from precision issues with large <em>n</em> due to floating-point arithmetic.</li>
</ul>
<h2>Conclusion:</h2>
<p>The provided solution is the most efficient in terms of both time and space for large values of <em>n</em>. It ensures a straightforward implementation with minimal memory usage, making it ideal for environments with tight space constraints.</p>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h2>Burhanuddin’s Code Compendium</h2>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Singleton Pattern with a Twist: Dual Instances in TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/singleton-pattern-with-a-twist</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/singleton-pattern-with-a-twist</guid>
            <pubDate>Thu, 29 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Mastering a Unique Singleton Design: Alternating Between Two Instances with Every Call</p>
<p><a href="https://medium.com/burhanuddins-code-compendium/singleton-pattern-with-a-twist-dual-instances-in-typescript-dab5f1ff8f60?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*vQJY2jv5vpAUfc1mHXJSGg.png" alt=""></a></p>
<h2>Problem</h2>
<p>Implement the singleton pattern with a twist. First, instead of storing one instance, store two instances. And in every even call of getInstance(), return the first instance and in every odd call of getInstance(), return the second instance.</p>
<h2>Problem Solution</h2>
<p>In traditional singleton patterns, only one instance of a class is created and shared throughout the application. However, in this task, we need to implement a singleton pattern that alternates between two instances. On every even call to getInstance(), it should return the first instance, and on every odd call, it should return the second instance.</p>
<h2>Step-by-Step Solution</h2>
<p>Let’s break down the problem and implement the solution in TypeScript:</p>
<p><strong>Class Structure:</strong></p>
<ul>
<li>We’ll create a class named TwistedSingleton.</li>
<li>Inside this class, we need two private static instance variables, instance1 and instance2, that will hold the two instances.</li>
<li>A static variable callCount will be used to keep track of the number of times getInstance() is called.</li>
</ul>
<p><strong>Constructor:</strong></p>
<ul>
<li>The constructor will be private to prevent direct instantiation.</li>
</ul>
<p><strong>getInstance Method:</strong></p>
<ul>
<li>The getInstance() method will Increment the callCount and Return instance1 if callCount is even, or instance2 if callCount is odd.</li>
<li>The first time the method is called, both instances will be created.</li>
</ul>
<h2>Implementation</h2>
<p>Here’s how this could be implemented in TypeScript:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name"><span class="token maybe-class-name">TwistedSingleton</span></span> <span class="token punctuation">{</span>
    <span class="token comment">// Static instances of the class</span>
    <span class="token class-name"><span class="token keyword">private</span></span> <span class="token keyword">static</span> instance1<span class="token operator">:</span> <span class="token maybe-class-name">TwistedSingleton</span> <span class="token operator">|</span> <span class="token keyword null nil">null</span> <span class="token operator">=</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> instance2<span class="token operator">:</span> <span class="token maybe-class-name">TwistedSingleton</span> <span class="token operator">|</span> <span class="token keyword null nil">null</span> <span class="token operator">=</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>

    <span class="token comment">// Counter to keep track of the calls to getInstance()</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> callCount<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">// Private constructor to prevent direct instantiation</span>
    <span class="token keyword">private</span> <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

    <span class="token comment">// Method to get the instance</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token maybe-class-name">TwistedSingleton</span> <span class="token punctuation">{</span>
        <span class="token comment">// Increment call count</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">callCount</span><span class="token operator">++</span><span class="token punctuation">;</span>

        <span class="token comment">// Create instances if they don't exist</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance1</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token maybe-class-name">TwistedSingleton</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance2</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance2</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token maybe-class-name">TwistedSingleton</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">// Return instance1 if call count is even, instance2 if odd</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">callCount</span> <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance1</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">instance2</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// Usage example</span>
<span class="token keyword">const</span> instanceA <span class="token operator">=</span> <span class="token maybe-class-name">TwistedSingleton</span><span class="token punctuation">.</span><span class="token method function property-access">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> instanceB <span class="token operator">=</span> <span class="token maybe-class-name">TwistedSingleton</span><span class="token punctuation">.</span><span class="token method function property-access">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> instanceC <span class="token operator">=</span> <span class="token maybe-class-name">TwistedSingleton</span><span class="token punctuation">.</span><span class="token method function property-access">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>instanceA <span class="token operator">===</span> instanceB<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false (instanceA is instance1, instanceB is instance2)</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>instanceB <span class="token operator">===</span> instanceC<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false (instanceB is instance2, instanceC is instance1)</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>instanceA <span class="token operator">===</span> instanceC<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true  (instanceA and instanceC are both instance1)</span>
</code></pre>
<h2>Explanation</h2>
<ul>
<li>Initialization: When the class is first accessed via getInstance(), both instance1 and instance2 are created.</li>
<li>Call Counting: The callCount variable ensures that the method alternates between returning instance1 and instance2.</li>
<li>Instance Return: Depending on whether the callCount is odd or even, the method returns either instance1 or instance2.</li>
</ul>
<h2>Alternative Solutions</h2>
<p>An alternative approach could involve using an array to store the instances and toggle between them using a modulus operation. However, this solution would not significantly differ in terms of efficiency or readability from the one provided above.</p>
<h2>Conclusion</h2>
<p>The dual-instance singleton pattern is a unique variation that allows alternating instances to be returned. This approach can be useful in scenarios where alternating resources or configurations are required.</p>
<p>This implementation provides a unique twist on the traditional singleton pattern, showcasing the flexibility and creativity that can be applied to classic design patterns.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h2>Burhanuddin’s Code Compendium</h2>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Efficient Flood Fill Algorithm in TypeScript: A Step-by-Step Guide]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/solving-the-flood-fill-algorithm</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/solving-the-flood-fill-algorithm</guid>
            <pubDate>Fri, 19 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>Step-by-Step Solution to Replace Colors in a 2D Matrix Using Depth-First Search</p>
<h2>Problem</h2>
<p>Given a 2-D matrix representing an image, a location of a pixel in the screen and a color C, replace the color of the given pixel and all adjacent same colored pixels with C.</p>
<p>For example, given the following matrix, and location pixel of (2, 2), and ‘G’ for green:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">W</span>
<span class="token constant">W</span> <span class="token constant">W</span> <span class="token constant">W</span>
<span class="token constant">W</span> <span class="token constant">W</span> <span class="token constant">W</span>
<span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">B</span>
</code></pre>
<p>Becomes</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">G</span>
<span class="token constant">G</span> <span class="token constant">G</span> <span class="token constant">G</span>
<span class="token constant">G</span> <span class="token constant">G</span> <span class="token constant">G</span>
<span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">B</span>
</code></pre>
<h2>Flood Fill Algorithm in TypeScript</h2>
<p>Flood fill is a classic algorithm used in computer graphics to determine the area connected to a given node in a multi-dimensional array. It is widely used in image editing software to implement the “bucket fill” tool, which fills a connected area with a single color.</p>
<h2>Problem Explanation</h2>
<p>Given a 2-D matrix representing an image, a location of a pixel in the screen, and a color C, we need to replace the color of the given pixel and all adjacent same-colored pixels with C.</p>
<p>Here’s the provided matrix and parameters:</p>
<p>Matrix:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">W</span>
<span class="token constant">W</span> <span class="token constant">W</span> <span class="token constant">W</span>
<span class="token constant">W</span> <span class="token constant">W</span> <span class="token constant">W</span>
<span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">B</span>
</code></pre>
<p>Starting pixel location: (2, 2)
New color: ‘G’ (Green)
After applying the flood fill algorithm, the matrix should transform into:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">G</span>
<span class="token constant">G</span> <span class="token constant">G</span> <span class="token constant">G</span>
<span class="token constant">G</span> <span class="token constant">G</span> <span class="token constant">G</span>
<span class="token constant">B</span> <span class="token constant">B</span> <span class="token constant">B</span>
</code></pre>
<h2>Step-by-Step Solution</h2>
<ol>
<li>Identify the Original Color: The color of the pixel at the given location.</li>
<li>Edge Cases: If the color to be changed is the same as the new color, return the matrix as is.</li>
<li>Use Depth-First Search (DFS): Recursively change the color of the starting pixel and its adjacent pixels (up, down, left, right) if they have the same color as the original pixel.</li>
</ol>
<h2>TypeScript Solution</h2>
<p>Here’s the implementation in TypeScript:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">floodFill</span><span class="token punctuation">(</span>matrix<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> sr<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> sc<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> newColor<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> originalColor <span class="token operator">=</span> matrix<span class="token punctuation">[</span>sr<span class="token punctuation">]</span><span class="token punctuation">[</span>sc<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>originalColor <span class="token operator">===</span> newColor<span class="token punctuation">)</span> <span class="token keyword control-flow">return</span> matrix<span class="token punctuation">;</span>

    <span class="token keyword">const</span> rows <span class="token operator">=</span> matrix<span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> cols <span class="token operator">=</span> matrix<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token property-access">length</span><span class="token punctuation">;</span>

    <span class="token keyword">function</span> <span class="token function">dfs</span><span class="token punctuation">(</span>r<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> c<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>r <span class="token operator">&lt;</span> <span class="token number">0</span> <span class="token operator">||</span> r <span class="token operator">&gt;=</span> rows <span class="token operator">||</span> c <span class="token operator">&lt;</span> <span class="token number">0</span> <span class="token operator">||</span> c <span class="token operator">&gt;=</span> cols <span class="token operator">||</span> matrix<span class="token punctuation">[</span>r<span class="token punctuation">]</span><span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">!==</span> originalColor<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword control-flow">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        matrix<span class="token punctuation">[</span>r<span class="token punctuation">]</span><span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">=</span> newColor<span class="token punctuation">;</span>

        <span class="token comment">// Recursively apply DFS in all 4 directions</span>
        <span class="token function">dfs</span><span class="token punctuation">(</span>r <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// down</span>
        <span class="token function">dfs</span><span class="token punctuation">(</span>r <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// up</span>
        <span class="token function">dfs</span><span class="token punctuation">(</span>r<span class="token punctuation">,</span> c <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// right</span>
        <span class="token function">dfs</span><span class="token punctuation">(</span>r<span class="token punctuation">,</span> c <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// left</span>
    <span class="token punctuation">}</span>

    <span class="token function">dfs</span><span class="token punctuation">(</span>sr<span class="token punctuation">,</span> sc<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword control-flow">return</span> matrix<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// Example usage</span>
<span class="token keyword">const</span> image <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">[</span><span class="token string">'B'</span><span class="token punctuation">,</span> <span class="token string">'B'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token string">'W'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token string">'W'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">[</span><span class="token string">'B'</span><span class="token punctuation">,</span> <span class="token string">'B'</span><span class="token punctuation">,</span> <span class="token string">'B'</span><span class="token punctuation">]</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> startRow <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> startCol <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> newColor <span class="token operator">=</span> <span class="token string">'G'</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> result <span class="token operator">=</span> <span class="token function">floodFill</span><span class="token punctuation">(</span>image<span class="token punctuation">,</span> startRow<span class="token punctuation">,</span> startCol<span class="token punctuation">,</span> newColor<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h2>Explanation</h2>
<ol>
<li>Original Color Identification: We first identify the original color of the pixel at the given location. If the original color is the same as the new color, we simply return the matrix as no changes are needed.</li>
<li>DFS Function: The DFS function changes the color of the current pixel and recursively does the same for all its adjacent pixels (up, down, left, right) if they match the original color.</li>
<li>Boundary Checks: Ensure that the DFS doesn’t go out of the matrix boundaries.</li>
</ol>
<blockquote>
<p>“Transformation often begins with the smallest pixel.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>
<p>By following this guide, you will be able to implement the flood fill algorithm in TypeScript, enabling efficient image processing and manipulation techniques.</p>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Tower of Hanoi Algorithm Solution in TypeScript]]></title>
            <link>https://burhanuddinhamzabhai.dev/coding-problems/solving-the-tower-of-hanoi-puzzle</link>
            <guid>https://burhanuddinhamzabhai.dev/coding-problems/solving-the-tower-of-hanoi-puzzle</guid>
            <pubDate>Thu, 05 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<p>A Step-by-Step Approach to Master the Classic Problem</p>
<p><a href="https://medium.com/burhanuddins-code-compendium/solving-the-tower-of-hanoi-puzzle-using-typescript-4c6a4f5d5bf8?source=rss-ac0d3c76ff4b------2"><img src="https://cdn-images-1.medium.com/max/1280/1*WpCtV8h8ZWZ-QPBlUfI-HQ.png" alt=""></a></p>
<h2>Problem</h2>
<p>The Tower of Hanoi is a puzzle game with three rods and n disks, each a different size.</p>
<p>All the disks start off on the first rod in a stack. They are ordered by size, with the largest disk on the bottom and the smallest one at the top.</p>
<p>The goal of this puzzle is to move all the disks from the first rod to the last rod while following these rules:</p>
<ul>
<li>You can only move one disk at a time.</li>
<li>A move consists of taking the uppermost disk from one of the stacks and placing it on top of another stack.</li>
<li>You cannot place a larger disk on top of a smaller disk.</li>
</ul>
<p>Write a function that prints out all the steps necessary to complete the Tower of Hanoi. You should assume that the rods are numbered, with the first rod being 1, the second (auxiliary) rod being 2, and the last (goal) rod being 3.</p>
<p>For example, with n = 3, we can do this in 7 moves:</p>
<pre><code>Move 1 to 3
Move 1 to 2
Move 3 to 2
Move 1 to 3
Move 2 to 1
Move 2 to 3
Move 1 to 3
</code></pre>
<hr>
<p>The Tower of Hanoi is a classic problem in computer science and mathematics. It involves moving disks of different sizes from one rod to another, following specific rules. The puzzle’s beauty lies in its simplicity and the recursive nature of its solution.</p>
<h2>Problem Explanation</h2>
<p>The Tower of Hanoi puzzle consists of three rods and n disks, each of a different size. Initially, all disks are stacked on the first rod, ordered by size, with the largest at the bottom and the smallest at the top. The goal is to move all the disks from the first rod to the third rod, following these rules:</p>
<ol>
<li>Only one disk can be moved at a time.</li>
<li>A disk can only be placed on top of a larger disk or an empty rod.</li>
<li>The disks must be moved following these constraints until all are transferred to the last rod.</li>
</ol>
<h2>Approach to the Solution</h2>
<p>The Tower of Hanoi is best solved using a recursive approach. The key idea is to break the problem into smaller subproblems. Here’s how you can think about it:</p>
<ol>
<li>Move n-1 disks from the first rod to the second rod using the third rod as an auxiliary.</li>
<li>Move the nth (largest) disk from the first rod to the third rod.</li>
<li>Finally, move the n-1 disks from the second rod to the third rod using the first rod as an auxiliary.</li>
</ol>
<h2>TypeScript Implementation</h2>
<p>Here’s how you can implement the Tower of Hanoi in TypeScript:</p>
<pre class="language-typescript"><code class="language-typescript"><span class="token keyword">function</span> <span class="token function">towerOfHanoi</span><span class="token punctuation">(</span>n<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> fromRod<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> toRod<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">,</span> auxRod<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{</span>
    <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>n <span class="token operator">===</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Move disk 1 from rod </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>fromRod<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> to rod </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>toRod<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword control-flow">return</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token function">towerOfHanoi</span><span class="token punctuation">(</span>n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">,</span> fromRod<span class="token punctuation">,</span> auxRod<span class="token punctuation">,</span> toRod<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Move disk </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>n<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> from rod </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>fromRod<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> to rod </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>toRod<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">towerOfHanoi</span><span class="token punctuation">(</span>n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">,</span> auxRod<span class="token punctuation">,</span> toRod<span class="token punctuation">,</span> fromRod<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// Example usage:</span>
<span class="token keyword">const</span> n <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span> <span class="token comment">// Number of disks</span>
<span class="token function">towerOfHanoi</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token maybe-class-name">Step</span><span class="token operator">-</span>by<span class="token operator">-</span><span class="token maybe-class-name">Step</span> <span class="token maybe-class-name">Explanation</span>
<span class="token maybe-class-name">Base</span> <span class="token maybe-class-name">Case</span><span class="token operator">:</span> <span class="token maybe-class-name">If</span> there <span class="token keyword">is</span> only one <span class="token function">disk</span> <span class="token punctuation">(</span>n <span class="token operator">===</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span> move it directly <span class="token keyword module">from</span> the source rod to the target rod<span class="token punctuation">.</span> <span class="token property-access"><span class="token maybe-class-name">This</span></span> <span class="token keyword">is</span> the simplest <span class="token keyword">case</span><span class="token punctuation">.</span>

<span class="token property-access"><span class="token maybe-class-name">Recursive</span></span> <span class="token maybe-class-name">Case</span><span class="token operator">:</span> <span class="token maybe-class-name">If</span> there are more than one disk<span class="token punctuation">,</span> the <span class="token keyword">function</span> calls itself twice<span class="token operator">:</span>

<span class="token maybe-class-name">First</span><span class="token punctuation">,</span> to move n<span class="token operator">-</span><span class="token number">1</span> disks <span class="token keyword module">from</span> the source rod to the auxiliary rod<span class="token punctuation">.</span>
<span class="token property-access"><span class="token maybe-class-name">Second</span></span><span class="token punctuation">,</span> to move the largest disk directly to the target rod<span class="token punctuation">.</span>
<span class="token property-access"><span class="token maybe-class-name">Finally</span></span><span class="token punctuation">,</span> it moves the n<span class="token operator">-</span><span class="token number">1</span> disks <span class="token keyword module">from</span> the auxiliary rod to the target rod<span class="token punctuation">.</span>
<span class="token property-access"><span class="token maybe-class-name">Output</span></span>
<span class="token maybe-class-name">For</span> n <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">,</span> the output will be<span class="token operator">:</span>

<span class="token maybe-class-name">Move</span> disk <span class="token number">1</span> <span class="token keyword module">from</span> rod <span class="token number">1</span> to rod <span class="token number">3</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">2</span> <span class="token keyword module">from</span> rod <span class="token number">1</span> to rod <span class="token number">2</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">1</span> <span class="token keyword module">from</span> rod <span class="token number">3</span> to rod <span class="token number">2</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">3</span> <span class="token keyword module">from</span> rod <span class="token number">1</span> to rod <span class="token number">3</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">1</span> <span class="token keyword module">from</span> rod <span class="token number">2</span> to rod <span class="token number">1</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">2</span> <span class="token keyword module">from</span> rod <span class="token number">2</span> to rod <span class="token number">3</span>
<span class="token maybe-class-name">Move</span> disk <span class="token number">1</span> <span class="token keyword module">from</span> rod <span class="token number">1</span> to rod <span class="token number">3</span>
</code></pre>
<h2>Conclusion</h2>
<p>The Tower of Hanoi problem is a brilliant example of how recursion can simplify complex problems. By breaking down the problem into smaller, manageable parts, you can achieve the goal with elegance. The TypeScript code provided offers a straightforward implementation that prints the sequence of moves needed to solve the puzzle.</p>
<blockquote>
<p>“Complex problems are best tackled by simplifying them into smaller, manageable tasks.” — <strong>Burhanuddin Mulla Hamzabhai</strong></p>
</blockquote>
<hr>
<p><a href="https://buymeacoffee.com/burhanuddinmullahamzabhai"><img src="https://cdn-images-1.medium.com/max/1024/1*QCQqlZr6doDP-cszzpaSpw.png" alt="If you like this, please think about buying me a coffee! ☕️."></a></p>
<h3>Burhanuddin’s Code Compendium</h3>
<p><em>Thank you for being a part of the</em> <a href="https://medium.com/burhanuddins-code-compendium"><strong><em>Burhanuddin’s Code Compendium</em></strong></a> <em>community! Before you go:</em></p>
<ul>
<li>Follow us: <a href="https://www.linkedin.com/in/burhanuddin-hamzabhai/"><strong>LinkedIn</strong></a> | <a href="https://youtube.com/@burhanuddinhamzabhai?si=MmXCG7p7C3hNpfV_"><strong>YouTube</strong></a>| <a href="https://medium.com/burhanuddins-code-chronicles/newsletters/chronicle-bytes"><strong>Newsletter</strong></a></li>
<li>Listen to our podcast on: <a href="https://open.spotify.com/show/6tTZbbaW5FfrqB2GeICzMV?si=b64356224c26434b"><strong>Spotify</strong></a>| <a href="https://music.amazon.in/podcasts/30d6d091-ecaa-442a-b3d4-1abc68d00206/code-symphony-unraveling-the-code-mysteries"><strong>Amazon Music</strong></a> <strong>|</strong> <a href="https://podcasts.apple.com/us/podcast/code-symphony-unraveling-the-code-mysteries/id1758484663"><strong>Apple Podcasts</strong></a></li>
<li>More content at <a href="https://medium.com/burhanuddins-code-compendium"><strong>Burhanuddin’s Code Compendium</strong></a></li>
</ul>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Breaking Free from Overthinking: Strategies to Liberate Your Mind]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/breaking-free-from-overthinking</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/breaking-free-from-overthinking</guid>
            <pubDate>Wed, 24 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Breaking Free from Overthinking: Strategies to Liberate Your Mind" loading="lazy" width="597" height="776" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fbreaking-free-from-overthinking.f95e2eb3.png&amp;w=640&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fbreaking-free-from-overthinking.f95e2eb3.png&amp;w=1200&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fbreaking-free-from-overthinking.f95e2eb3.png&amp;w=1200&amp;q=75">
<h2>Understand the Root Causes</h2>
<p>Overthinking often stems from fear, anxiety, and a desire for control. Identifying these underlying causes is the first step toward addressing them effectively.</p>
<h2>Embrace Imperfection</h2>
<p>Perfectionism can drive overthinking. Accept that mistakes are part of growth and learning. Striving for excellence is good, but expecting perfection is unrealistic.</p>
<h2>Set Time Limits for Decisions</h2>
<p>Allocate a specific amount of time for making decisions. This helps in preventing endless deliberation and encourages quicker, more confident choices.</p>
<h2>Practice Mindfulness</h2>
<p>Mindfulness exercises, such as meditation and deep breathing, can help calm your mind and bring your focus back to the present moment, reducing the tendency to overthink.</p>
<h2>Challenge Negative Thoughts</h2>
<p>When you catch yourself overthinking, question the validity of your thoughts. Are they based on facts or assumptions? This helps in breaking the cycle of negative thinking.</p>
<h2>Take Action</h2>
<p>Overthinking often leads to inaction. Combat this by taking small, manageable steps toward your goals. Action can help clear your mind and reduce anxiety.</p>
<h2>Limit Information Intake</h2>
<p>In the digital age, we are bombarded with information. Limit your intake to what is necessary to avoid becoming overwhelmed and overthinking every detail.</p>
<h2>Cultivate a Growth Mindset</h2>
<p>Adopt a mindset that views challenges and failures as opportunities for growth rather than setbacks. This perspective reduces the fear of making mistakes, a common trigger for overthinking.</p>
<h2>Practice Gratitude</h2>
<p>Focus on what you are grateful for. This shift in mindset can help reduce negative thinking patterns and bring a more positive outlook to your daily life.</p>
<h2>Seek Support</h2>
<p>Talking to friends, family, or a mental health professional can provide you with new perspectives and help you break free from the cycle of overthinking.</p>
<h2>Engage in Creative Activities</h2>
<p>Creative outlets like drawing, writing, or playing an instrument can distract your mind from overthinking and provide a healthy way to express your thoughts and emotions.</p>
<blockquote>
<p>"Free your mind from the shackles of overthinking, and you'll unlock a world of endless possibilities." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Embrace Pain: Turning Life Trials into Triumphs]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/embrace-pain</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/embrace-pain</guid>
            <pubDate>Sat, 20 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Embrace Pain: Turning Life's Trials into Triumphs" loading="lazy" width="1327" height="893" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fembrace-pain.2bd59b56.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fembrace-pain.2bd59b56.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fembrace-pain.2bd59b56.png&amp;w=3840&amp;q=75">
<h2>Pain as a Catalyst for Change</h2>
<p>Pain often triggers significant life changes, pushing us to reassess our goals and values.</p>
<h2>Strength Through Adversity</h2>
<p>Facing and overcoming pain builds inner strength, enhancing our resilience and fortitude.</p>
<h2>Cultivating Compassion</h2>
<p>Experiencing pain deepens our compassion for others, helping us relate to and support those in similar situations.</p>
<h2>Learning and Growth</h2>
<p>Painful experiences are rich with lessons, teaching us about our limits, capabilities, and true selves.</p>
<h2>Building Emotional Intelligence</h2>
<p>Navigating pain improves our emotional intelligence, aiding in better understanding and managing our emotions.</p>
<h2>Fostering Gratitude</h2>
<p>Pain can make us appreciate the positive aspects of life more deeply, fostering a sense of gratitude and contentment.</p>
<h2>Enhancing Problem-Solving Skills</h2>
<p>Overcoming challenges sharpens our problem-solving abilities, preparing us for future obstacles.</p>
<h2>Promoting Self-Awareness</h2>
<p>Pain forces introspection, leading to greater self-awareness and understanding of our own needs and desires.</p>
<h2>Encouraging Personal Responsibility</h2>
<p>Confronting pain can help us take responsibility for our actions and decisions, leading to personal growth.</p>
<h2>Strengthening Relationships</h2>
<p>Sharing our pain with others can strengthen relationships through vulnerability and mutual support.</p>
<h2>Finding Purpose</h2>
<p>Pain can lead us to discover new purposes and passions, aligning our lives with deeper meaning and fulfillment.</p>
<blockquote>
<p>"Pain is the crucible of transformation, molding us into stronger, wiser beings." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[The Hidden Guide: How Jealousy Can Illuminate Your True Path]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/how-jealousy-can-illuminate-the-path</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/how-jealousy-can-illuminate-the-path</guid>
            <pubDate>Tue, 20 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on The Hidden Guide: How Jealousy Can Illuminate Your True Path" loading="lazy" width="1341" height="887" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fhow-jealousy-can-illuminate-the-path.a5369f9d.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fhow-jealousy-can-illuminate-the-path.a5369f9d.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fhow-jealousy-can-illuminate-the-path.a5369f9d.png&amp;w=3840&amp;q=75">
<h2>Jealousy as a Mirror</h2>
<p>Jealousy often reflects what we truly desire but may not admit to ourselves. It’s a mirror that shows us our deepest aspirations.</p>
<h2>Identify Your True Wants</h2>
<p>When you feel jealous, ask yourself why. What is it about the other person’s life or achievements that you want for yourself?</p>
<h2>Turn Jealousy into Motivation</h2>
<p>Use the energy of jealousy to fuel your own goals. Instead of resenting others, let their success inspire you to work harder.</p>
<h2>Understand the Root Cause</h2>
<p>Sometimes jealousy stems from insecurity or fear. Understanding the root cause can help you address those feelings and focus on self-improvement.</p>
<h2>Jealousy as a Wake-Up Call</h2>
<p>Jealousy can be a signal that you’re not living your life in alignment with your true desires. It’s a wake-up call to make changes.</p>
<h2>Develop a Plan</h2>
<p>Once you’ve identified what jealousy is telling you, create a plan to achieve those desires. Set realistic goals and take actionable steps.</p>
<h2>Celebrate Others’ Success</h2>
<p>Instead of feeling bitter, celebrate others’ achievements. This shift in mindset can reduce negative emotions and open up opportunities for growth.</p>
<h2>Focus on Your Journey</h2>
<p>Everyone’s path is different. Use jealousy as a reminder to focus on your own journey and not compare yourself to others.</p>
<h2>Learn from What You Admire</h2>
<p>What you admire in others can often be developed within yourself. Identify those traits and work on cultivating them.</p>
<h2>Practice Gratitude</h2>
<p>Shift your focus from what you lack to what you have. Practicing gratitude can diminish feelings of jealousy and enhance overall well-being.</p>
<h2>Jealousy as a Guide, Not an Enemy</h2>
<p>Recognize jealousy as a tool for self-discovery and growth. It’s not your enemy but a guide showing you where you truly want to go.</p>
<blockquote>
<p>"Jealousy is not a shadow of weakness, but a beacon that lights up the path you secretly desire to walk." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Illuminate Your Day: 11 Unique Habits to Cultivate Daily Positivity]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/illuminate-your-day</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/illuminate-your-day</guid>
            <pubDate>Thu, 18 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Illuminate Your Day: 11 Unique Habits to Cultivate Daily Positivity" loading="lazy" width="1343" height="882" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Filluminate-your-day.0b2879bb.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Filluminate-your-day.0b2879bb.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Filluminate-your-day.0b2879bb.png&amp;w=3840&amp;q=75">
<h2>Create a "Joy Jar"</h2>
<p>Each day, write down something that made you smile and put it in a jar. On tough days, revisit these notes to remind yourself of the joyful moments.</p>
<h2>Practice Digital Detox Periods</h2>
<p>Schedule specific times during the day to disconnect from all digital devices. Use this time to read, meditate, or simply relax without distractions.</p>
<h2>Adopt a Plant and Nurture It</h2>
<p>Taking care of a plant can be therapeutic. Choose a plant that requires regular attention and make it part of your daily routine to care for it.</p>
<h2>Engage in Random Acts of Kindness</h2>
<p>Make it a goal to perform at least one random act of kindness each day. This could be as simple as complimenting a stranger or helping a neighbor.</p>
<h2>Establish a Morning Ritual</h2>
<p>Create a morning ritual that energizes and inspires you. This could include stretching, a nutritious breakfast, and a few minutes of journaling.</p>
<h2>Declutter a Small Space</h2>
<p>Spend a few minutes each day decluttering a small area in your home. A clean, organized space can significantly enhance your mental clarity and positivity.</p>
<h2>Practice "Mirror Work" Affirmations</h2>
<p>Stand in front of a mirror each day and speak positive affirmations to yourself. This practice can boost self-esteem and reinforce a positive self-image.</p>
<h2>Enjoy a Creative Break</h2>
<p>Dedicate time each day to a creative activity like drawing, writing, or crafting. Creative expression is a powerful way to boost your mood and reduce stress.</p>
<h2>Explore New Music</h2>
<p>Discover and listen to new music genres or artists. Music has a profound impact on our emotions and can be a great source of joy and relaxation.</p>
<h2>Cultivate Mindful Eating</h2>
<p>Practice mindful eating by paying full attention to the taste, texture, and aroma of your food. This can enhance your appreciation for meals and promote a positive eating experience.</p>
<h2>End the Day with Reflection</h2>
<p>Before going to bed, take a few minutes to reflect on the positive aspects of your day. Consider what went well and what you're looking forward to tomorrow.</p>
<blockquote>
<p>"Positivity doesn't happen by chance. It’s a daily choice to find joy, embrace mindfulness, and spread kindness." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Mastering the Art of Not Taking Things Personally]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-not-taking-things-personally</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-not-taking-things-personally</guid>
            <pubDate>Tue, 03 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on The Mastering the Art of Not Taking Things Personally" loading="lazy" width="1363" height="897" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-not-taking-things-personally.453febc3.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-not-taking-things-personally.453febc3.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-not-taking-things-personally.453febc3.png&amp;w=3840&amp;q=75">
<h2>Understand It's Not About You</h2>
<p>Most of the time, people's reactions reflect their own issues, not yours. Realizing this can be the first step toward not taking things personally.</p>
<h2>Build Self-Awareness</h2>
<p>Know your triggers. By understanding what makes you sensitive, you can work on desensitizing yourself and reacting calmly.</p>
<h2>Practice Emotional Detachment</h2>
<p>Separate your self-worth from external opinions. Remember, your value isn't dictated by others' thoughts.</p>
<h2>Learn to Respond, Not React</h2>
<p>When faced with criticism, pause and reflect before responding. This helps in reducing the emotional impact.</p>
<h2>Empathy Goes a Long Way</h2>
<p>Try to understand the other person's perspective. Often, their behavior is a result of something deeper.</p>
<h2>Develop a Growth Mindset</h2>
<p>See criticism as an opportunity to grow rather than a personal attack. It shifts your focus from defense to improvement.</p>
<h2>Set Boundaries</h2>
<p>Protect your emotional space by setting clear boundaries. This helps in reducing the chances of taking things to heart.</p>
<h2>Engage in Positive Self-Talk</h2>
<p>Counter negative comments with positive affirmations about yourself. This reinforces your self-esteem.</p>
<h2>Remember Your Purpose</h2>
<p>Keep your goals and values at the forefront. This focus will help you stay grounded and unaffected by minor setbacks.</p>
<h2>Surround Yourself with Support</h2>
<p>Engage with people who uplift and support you. Their positive influence will help you stay resilient.</p>
<h2>Practice Mindfulness</h2>
<p>Stay present and aware of your emotions. Mindfulness helps you recognize when you're starting to take things personally and allows you to refocus.</p>
<blockquote>
<p>"Your worth is not determined by the opinions of others, but by the strength of your inner voice." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Mastering the Art of Self-Containment]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-self-containment</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-self-containment</guid>
            <pubDate>Tue, 17 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Mastering the Art of Self-Containment" loading="lazy" width="598" height="646" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-containment.252f084a.png&amp;w=640&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-containment.252f084a.png&amp;w=1200&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-containment.252f084a.png&amp;w=1200&amp;q=75">
<h2>Pause and Reflect</h2>
<p>Before reacting, take a deep breath and reflect. This helps you stay calm and gives you the clarity to respond thoughtfully, not impulsively.</p>
<h2>Embrace Emotional Awareness</h2>
<p>Understanding your emotions is key. When you can identify what you're feeling, it becomes easier to control your reactions.</p>
<h2>Set Boundaries for Yourself</h2>
<p>Establish clear limits for how you interact with others and situations. This helps protect your mental energy and keeps you grounded.</p>
<h2>Practice Patience</h2>
<p>Patience is a vital skill in self-containment. Practice it daily by being mindful of moments when you tend to rush or get frustrated.</p>
<h2>Develop a Mindfulness Routine</h2>
<p>Meditation or mindful breathing can help train your mind to stay focused and composed, even in stressful situations.</p>
<h2>Learn to Let Go</h2>
<p>Not every situation requires a reaction. Train yourself to let go of things beyond your control to preserve your peace of mind.</p>
<h2>Stay Grounded with Self-Discipline</h2>
<p>Create habits that reinforce self-discipline—whether it's in your work routine, health, or personal relationships. Discipline fosters self-containment.</p>
<h2>Communicate Assertively, Not Aggressively</h2>
<p>If you need to express yourself, do it in a calm and assertive manner. Avoid letting emotions turn into aggression.</p>
<h2>Seek Solutions, Not Conflicts</h2>
<p>Focus on resolving problems rather than getting caught up in emotional disputes. This mindset shift helps you remain level-headed.</p>
<h2>Surround Yourself with Positivity</h2>
<p>Stay around people who bring out the best in you. Positive environments reinforce your ability to maintain self-control.</p>
<h2>Reflect on Your Progress</h2>
<p>Regularly assess your personal growth in self-containment. Celebrate your wins and recognize areas to improve.</p>
<blockquote>
<p>"The art of self-containment is not in suppressing your emotions, but in channeling them toward positive outcomes." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Mastering the Art of Self-Preservation: You Cannot Please Everyone]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-self-preservation</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/mastering-the-art-of-self-preservation</guid>
            <pubDate>Tue, 06 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Mastering the Art of Self-Preservation: You Can't Please Everyone" loading="lazy" width="1356" height="891" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-preservation.85cafd19.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-preservation.85cafd19.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fmastering-the-art-of-self-preservation.85cafd19.png&amp;w=3840&amp;q=75">
<h2>Accept Your Limitations</h2>
<p>Understand that it's impossible to meet everyone's expectations. Recognize your boundaries and prioritize your well-being.</p>
<h2>Define Your Values</h2>
<p>Identify what truly matters to you. Let your values guide your decisions, ensuring that your actions align with your beliefs rather than others' opinions.</p>
<h2>Embrace Authenticity</h2>
<p>Stay true to yourself. Authenticity attracts genuine connections and fosters a sense of fulfillment that external approval cannot provide.</p>
<h2>Set Boundaries</h2>
<p>Establish clear boundaries to protect your time and energy. Communicate these boundaries assertively to avoid being overwhelmed by others' demands.</p>
<h2>Focus on Quality Relationships</h2>
<p>Invest in relationships that uplift and support you. Surround yourself with people who respect and appreciate you for who you are.</p>
<h2>Practice Self-Compassion</h2>
<p>Be kind to yourself. Acknowledge your efforts and progress, even if they don't always lead to universal approval.</p>
<h2>Learn to Say No</h2>
<p>Saying no is a powerful tool for maintaining balance. Decline requests that conflict with your values or deplete your resources.</p>
<h2>Let Go of Perfectionism</h2>
<p>Perfectionism often stems from a desire to please everyone. Accept that mistakes and imperfections are part of growth and learning.</p>
<h2>Seek Constructive Feedback</h2>
<p>Value feedback from trusted sources that aim to help you improve. Disregard criticism that lacks constructive intent or comes from people who don't have your best interests at heart.</p>
<h2>Celebrate Your Uniqueness</h2>
<p>Embrace what makes you different. Your unique perspective and abilities contribute to a diverse and vibrant world.</p>
<h2>Prioritize Self-Care</h2>
<p>Dedicate time to activities that rejuvenate and energize you. Self-care is essential for maintaining mental and emotional health.</p>
<blockquote>
<p>"Authenticity is the daily practice of letting go of who we think we're supposed to be and embracing who we are." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Rediscovering Self-Love: A Journey to Reconnect with Yourself]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/rediscovering-self-love</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/rediscovering-self-love</guid>
            <pubDate>Tue, 30 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Rediscovering Self-Love: A Journey to Reconnect with Yourself" loading="lazy" width="796" height="530" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Frediscovering-self-love.b64723bd.png&amp;w=828&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Frediscovering-self-love.b64723bd.png&amp;w=1920&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Frediscovering-self-love.b64723bd.png&amp;w=1920&amp;q=75">
<h2>Acknowledge Your Worth</h2>
<p>Recognize that you are inherently valuable. Embrace your uniqueness and celebrate the qualities that make you who you are.</p>
<h2>Practice Self-Compassion</h2>
<p>Be kind to yourself. Forgive your mistakes and learn from them. Treat yourself with the same understanding and patience you would offer a friend.</p>
<h2>Set Healthy Boundaries</h2>
<p>Learn to say no without feeling guilty. Protect your energy and prioritize your well-being by setting clear boundaries in your relationships and commitments.</p>
<h2>Engage in Activities You Enjoy</h2>
<p>Rediscover hobbies and activities that bring you joy. Whether it’s painting, reading, hiking, or dancing, make time for what you love.</p>
<h2>Surround Yourself with Positivity</h2>
<p>Spend time with people who uplift and support you. Positive relationships can reinforce your sense of self-worth and happiness.</p>
<h2>Focus on Personal Growth</h2>
<p>Set goals for self-improvement. Continuous learning and personal development can boost your confidence and help you become the best version of yourself.</p>
<h2>Practice Mindfulness and Meditation</h2>
<p>Take time to be present and mindful. Meditation can help you connect with your inner self and find peace amidst the chaos of everyday life.</p>
<h2>Celebrate Small Wins</h2>
<p>Acknowledge and celebrate your achievements, no matter how small they may seem. Recognizing your progress reinforces your self-worth.</p>
<h2>Embrace Your Imperfections</h2>
<p>Accept that no one is perfect. Embrace your flaws and understand that they are part of what makes you human and relatable.</p>
<h2>Nurture Your Body</h2>
<p>Take care of your physical health through regular exercise, a balanced diet, and adequate rest. A healthy body can significantly impact your mental and emotional well-being.</p>
<h2>Reflect on Your Journey</h2>
<p>Take time to reflect on your personal journey. Understand how far you’ve come and appreciate the lessons you’ve learned along the way.</p>
<blockquote>
<p>"True self-love is not about perfection, but about accepting and loving your imperfect self." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[The Hidden Power of Small Things: Reframing Failure and Cherishing Life]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/the-hidden-power-of-small-things</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/the-hidden-power-of-small-things</guid>
            <pubDate>Mon, 22 Jul 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on The Hidden Power of Small Things: Reframing Failure and Cherishing Life" loading="lazy" width="1345" height="877" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-hidden-power-of-small-things.44296cf3.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-hidden-power-of-small-things.44296cf3.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-hidden-power-of-small-things.44296cf3.png&amp;w=3840&amp;q=75">
<h2>The Butterfly Effect</h2>
<p>Small actions can lead to significant outcomes. A tiny change in your routine, like a morning walk, can drastically improve your mental health over time.</p>
<h2>Appreciating the Present</h2>
<p>Cherishing small moments, such as a warm cup of coffee or a sunset, helps you stay grounded and appreciate life’s simple pleasures.</p>
<h2>Mindfulness and Gratitude</h2>
<p>Practicing mindfulness makes you aware of the little things around you. Gratitude journals help in recognizing these small yet impactful elements of life.</p>
<h2>Reframing Failure as Feedback</h2>
<p>Viewing failure as feedback rather than defeat helps you learn and grow. Each setback becomes an opportunity for improvement.</p>
<h2>Incremental Progress</h2>
<p>Small, consistent efforts lead to significant achievements. Whether it’s learning a new skill or building a habit, every tiny step counts.</p>
<h2>The Power of a Smile</h2>
<p>A smile can brighten someone’s day and improve your mood. It’s a small gesture with profound impact.</p>
<h2>Acts of Kindness</h2>
<p>Small acts of kindness, like holding the door for someone or giving a compliment, create a ripple effect of positivity.</p>
<h2>Building Resilience</h2>
<p>Overcoming small challenges strengthens your resilience. Each victory, no matter how minor, builds your confidence to face bigger obstacles.</p>
<h2>The Joy of Little Surprises</h2>
<p>Surprising a friend with a note or a small gift can create lasting memories and strengthen your relationships.</p>
<h2>Embracing Imperfections</h2>
<p>Accepting and cherishing imperfections in yourself and others fosters a more compassionate and realistic outlook on life.</p>
<h2>Cultivating a Growth Mindset</h2>
<p>Believing that abilities and intelligence can be developed through dedication and hard work transforms failures into learning experiences.</p>
<blockquote>
<p>"In the grand tapestry of life, it’s the small threads that weave the most intricate patterns." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[The Paradox of Attachment: Losing Yourself in the Process]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/the-paradox-of-attachment</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/the-paradox-of-attachment</guid>
            <pubDate>Tue, 13 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on The Paradox of Attachment: Losing Yourself in the Process" loading="lazy" width="1343" height="892" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-paradox-of-attachment.b1996469.png&amp;w=1920&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-paradox-of-attachment.b1996469.png&amp;w=3840&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fthe-paradox-of-attachment.b1996469.png&amp;w=3840&amp;q=75">
<h2>Attachment Defined</h2>
<p>Attachment often begins as a connection that brings warmth and comfort, but it can evolve into a dependence that distances us from our true selves.</p>
<h2>The Illusion of Security</h2>
<p>We often attach ourselves to people, objects, or ideas because they give us a false sense of security, masking our inner vulnerabilities.</p>
<h2>Emotional Dependency</h2>
<p>Over time, attachment can lead to emotional dependency, where our happiness and identity become tied to something or someone external.</p>
<h2>Self-Neglect</h2>
<p>In the process of attaching, we may start to neglect our own needs, desires, and growth, prioritizing the attachment over ourselves.</p>
<h2>The Fear of Loss</h2>
<p>Attachment brings with it the fear of losing the object of our attachment, which can create anxiety and a constant state of unrest.</p>
<h2>Identity Shift</h2>
<p>As we become more attached, our identity begins to shift, blending with the object of our attachment, leading to a loss of self-awareness.</p>
<h2>The Cycle of Attachment</h2>
<p>The more we attach, the more we detach from our inner selves, creating a cycle where we continually seek external validation and comfort.</p>
<h2>Mindful Attachment</h2>
<p>To avoid losing ourselves, it’s essential to practice mindful attachment—where we connect deeply but remain grounded in our own identity.</p>
<h2>Healthy Boundaries</h2>
<p>Setting healthy boundaries in relationships and with material possessions can prevent attachment from turning into a source of self-detachment.</p>
<h2>Rediscovering Self</h2>
<p>The journey of rediscovering oneself often begins with recognizing the attachments that have led to self-neglect and consciously choosing to reconnect with our inner being.</p>
<h2>Embracing Non-Attachment</h2>
<p>Non-attachment doesn’t mean disconnecting entirely but rather finding balance, where we can love and connect without losing ourselves in the process.</p>
<blockquote>
<p>"True connection is not about losing yourself in another, but about finding yourself amidst the connection." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[Why Forever is a Myth: Embracing the Impermanence of Life]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/why-forever-is-a-myth</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/why-forever-is-a-myth</guid>
            <pubDate>Tue, 27 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on Why Forever is a Myth: Embracing the Impermanence of Life" loading="lazy" width="721" height="510" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fwhy-forever-is-a-myth.5ce80cb9.png&amp;w=750&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fwhy-forever-is-a-myth.5ce80cb9.png&amp;w=1920&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fwhy-forever-is-a-myth.5ce80cb9.png&amp;w=1920&amp;q=75">
<h2>Impermanence is Natural</h2>
<p>Everything in life is temporary, from emotions to relationships. Understanding this can help us appreciate the present.</p>
<h2>Growth Happens in Change</h2>
<p>We evolve through experiences. If everything were forever, growth would stagnate.</p>
<h2>Attachment Breeds Suffering</h2>
<p>Holding onto the idea of forever can cause pain. Embrace the flow of life instead.</p>
<h2>Enjoy the Moment</h2>
<p>When we let go of the need for things to last forever, we start living fully in the moment.</p>
<h2>Relationships Evolve</h2>
<p>People change, and so do relationships. Accepting this can lead to healthier, more fulfilling connections.</p>
<h2>Success is Not Permanent</h2>
<p>Achievements come and go. What matters is the journey, not the permanence of success.</p>
<h2>Learn from Loss</h2>
<p>Every end is a new beginning. Losses teach us valuable lessons about resilience and renewal.</p>
<h2>Expectations vs. Reality</h2>
<p>The idea of forever often clashes with reality, leading to disappointment. Embrace life as it is.</p>
<h2>Freedom in Letting Go</h2>
<p>When we stop clinging to forever, we gain the freedom to explore new possibilities.</p>
<h2>Embrace Change</h2>
<p>Change is the only constant. Adapting to it allows us to thrive in an ever-evolving world.</p>
<h2>Live Authentically</h2>
<p>Instead of striving for forever, focus on living a life true to yourself, moment by moment.</p>
<blockquote>
<p>"Forever is an illusion; the beauty of life lies in its fleeting moments." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
        <item>
            <title><![CDATA[You Cannot Be Her Everything: Embracing Healthy Relationships]]></title>
            <link>https://burhanuddinhamzabhai.dev/thought-bites/you-cannot-be-her-everything</link>
            <guid>https://burhanuddinhamzabhai.dev/thought-bites/you-cannot-be-her-everything</guid>
            <pubDate>Tue, 10 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<img alt="Article on You Cannot Be Her Everything: Embracing Healthy Relationships" loading="lazy" width="790" height="522" decoding="async" data-nimg="1" style="color:transparent" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fyou-cannot-be-her-everything.44fee588.png&amp;w=828&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fyou-cannot-be-her-everything.44fee588.png&amp;w=1920&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fyou-cannot-be-her-everything.44fee588.png&amp;w=1920&amp;q=75">
<h2>No One Person Can Fulfill Every Need</h2>
<p>One partner cannot provide everything—emotional, social, or intellectual fulfillment. Realizing this helps avoid unrealistic expectations.</p>
<h2>Healthy Relationships Encourage Growth</h2>
<p>In a strong relationship, both individuals grow independently and support each other's personal development, not stunt it.</p>
<h2>Embrace Your Own Interests</h2>
<p>Retain hobbies and passions that are personal to you. This adds variety to your life and ensures you remain a whole individual within the relationship.</p>
<h2>Avoid Emotional Dependency</h2>
<p>Relying solely on your partner for emotional support can lead to codependency. Both partners need to cultivate emotional resilience.</p>
<h2>Relationships Should Complement, Not Complete</h2>
<p>A relationship is healthiest when it enhances your life, not when it becomes your whole identity. Be someone who shares a journey, not a crutch.</p>
<h2>Respect Her Need for Space</h2>
<p>Everyone needs personal space and time for self-reflection. Being overly involved in every aspect of her life may lead to burnout and resentment.</p>
<h2>Encourage Friendships Outside the Relationship</h2>
<p>Both of you should have your own circle of friends. It maintains social diversity and takes the pressure off of one person being the sole companion.</p>
<h2>Love Without Losing Yourself</h2>
<p>It's important to nurture your identity and passions. A healthy love allows both partners to remain true to themselves.</p>
<h2>Trust is Key</h2>
<p>Trusting your partner to seek fulfillment from other healthy sources, like friends or hobbies, strengthens the bond and avoids jealousy.</p>
<h2>Self-Care is Essential</h2>
<p>Taking care of yourself mentally, emotionally, and physically ensures you bring your best self to the relationship.</p>
<h2>A Relationship is a Partnership, Not Ownership</h2>
<p>Love thrives when both individuals respect each other’s independence. You're partners, not possessors.</p>
<blockquote>
<p>"A healthy relationship is when two people make space for each other’s worlds and still find each other in the middle." - <strong>BURHANUDDIN MULLA HAMZABHAI</strong></p>
</blockquote>]]></content:encoded>
            <author>burhanuddinhamzabhai@gmail.com (Burhanuddin Mulla Hamzabhai)</author>
        </item>
    </channel>
</rss>