<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arun Prakash Pandey</title>
    <description>The latest articles on DEV Community by Arun Prakash Pandey (@d32ssv).</description>
    <link>https://dev.to/d32ssv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1084640%2F4fbbeb1e-7db5-4bc9-ac06-7986bbb66370.png</url>
      <title>DEV Community: Arun Prakash Pandey</title>
      <link>https://dev.to/d32ssv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/d32ssv"/>
    <language>en</language>
    <item>
      <title>REPL means Read, Evaluate, Print, Loop</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Fri, 10 Jul 2026 06:07:36 +0000</pubDate>
      <link>https://dev.to/d32ssv/repl-means-read-evaluate-print-loop-1d7m</link>
      <guid>https://dev.to/d32ssv/repl-means-read-evaluate-print-loop-1d7m</guid>
      <description>&lt;h3&gt;
  
  
  Why oh why? 😂
&lt;/h3&gt;

&lt;p&gt;Ever wondered, why &lt;em&gt;undefined&lt;/em&gt; is logged whenever you're messing around within a Browser's Dev Tools or any other JS run time environment?&lt;br&gt;
Then this is for you!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;node

Welcome to Node.js v22.22.2.

Type ".help" for more information.

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;let &lt;/span&gt;x &lt;span class="o"&gt;=&lt;/span&gt; 45&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="go"&gt;
undefined

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;let &lt;/span&gt;y &lt;span class="o"&gt;=&lt;/span&gt; 78
&lt;span class="go"&gt;
undefined

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;456 &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;y&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;78
&lt;span class="go"&gt;
true

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;console.log&lt;span class="o"&gt;(&lt;/span&gt;x&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="go"&gt;
45

undefined

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  TLDR
&lt;/h3&gt;

&lt;p&gt;The output received after evaluation.&lt;/p&gt;

&lt;h3&gt;
  
  
  The phenomena
&lt;/h3&gt;

&lt;p&gt;The host environment prints the result of every expression.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expression : (x === 456 || y === 78)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;prints the result &lt;em&gt;true&lt;/em&gt; but no &lt;em&gt;undefined&lt;/em&gt; was printed!&lt;/p&gt;

&lt;p&gt;However, the statements like below do not return a value.&lt;br&gt;
&lt;code&gt;let x = 45;&lt;/code&gt; OR &lt;code&gt;console.log(x)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;the above statement did not return any value, causing &lt;em&gt;"undefined"&lt;/em&gt; to be printed in the logs.&lt;/p&gt;
&lt;h3&gt;
  
  
  The cause
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Because the host environment is in it's interactive mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, understand that &lt;code&gt;console.log()&lt;/code&gt; is not the main purpose here, it is a "&lt;em&gt;side effect&lt;/em&gt;". &lt;br&gt;
The main purpose is evaluation of the latest expression. Imagine the REPL environment effectively acting like this behind the scenes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 1. it takes your code string (input), &lt;/span&gt;
&lt;span class="c1"&gt;// 2. evaluates it (via eval()), and &lt;/span&gt;
&lt;span class="c1"&gt;// 3. returns the result&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;executeInREPL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if you do &lt;code&gt;console.log(x)&lt;/code&gt;, it would print the value of &lt;em&gt;"x"&lt;/em&gt; but since the evaluation did not &lt;em&gt;"return"&lt;/em&gt; any value, &lt;em&gt;"undefined"&lt;/em&gt; will be logged additionally.&lt;/p&gt;

&lt;p&gt;So, the final cause is the result of &lt;strong&gt;&lt;em&gt;evaluation&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Things you did not knew about JS- Part-1</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Fri, 10 Jul 2026 05:35:39 +0000</pubDate>
      <link>https://dev.to/d32ssv/things-you-did-not-knew-about-js-part-1-4mgf</link>
      <guid>https://dev.to/d32ssv/things-you-did-not-knew-about-js-part-1-4mgf</guid>
      <description>&lt;h3&gt;
  
  
  When dinosaurs lived:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript's design was influenced by several programming languages: namely Scheme, Self, Java, C, Perl.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The core language does &lt;strong&gt;"NOT"&lt;/strong&gt; includes:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Read keyboard input&lt;/li&gt;
&lt;li&gt;Display output on a screen&lt;/li&gt;
&lt;li&gt;Access the file system&lt;/li&gt;
&lt;li&gt;Make HTTP requests&lt;/li&gt;
&lt;li&gt;Manipulate web pages&lt;/li&gt;
&lt;li&gt;Create windows or dialogs
These capabilities are provided by the host environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Host Environment means the web browser, Or Node.js (a run time &lt;em&gt;"environment"&lt;/em&gt;).
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Host environments provide I/O
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Web Browser

&lt;ul&gt;
&lt;li&gt;console.log()&lt;/li&gt;
&lt;li&gt;document&lt;/li&gt;
&lt;li&gt;window&lt;/li&gt;
&lt;li&gt;fetch()&lt;/li&gt;
&lt;li&gt;alert()&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Node.js

&lt;ul&gt;
&lt;li&gt;console.log()&lt;/li&gt;
&lt;li&gt;fs&lt;/li&gt;
&lt;li&gt;http&lt;/li&gt;
&lt;li&gt;process&lt;/li&gt;
&lt;li&gt;readline&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Although console.log() is commonly used, it is not part of the ECMAScript specification. It is provided by browsers, Node.js, and other JavaScript environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  The core language includes:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Numbers (Number, BigInt)&lt;/li&gt;
&lt;li&gt;Text (String)&lt;/li&gt;
&lt;li&gt;Booleans (Boolean)&lt;/li&gt;
&lt;li&gt;Arrays (Array)&lt;/li&gt;
&lt;li&gt;Objects (Object)&lt;/li&gt;
&lt;li&gt;Sets (Set)&lt;/li&gt;
&lt;li&gt;Maps (Map)&lt;/li&gt;
&lt;li&gt;Dates (Date)&lt;/li&gt;
&lt;li&gt;Regular expressions (RegExp)&lt;/li&gt;
&lt;li&gt;Promises (Promise)&lt;/li&gt;
&lt;li&gt;JSON&lt;/li&gt;
&lt;li&gt;Math utilities (Math)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Most Common Uses
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;One of Node.js's most common uses is building web servers and APIs.&lt;/li&gt;
&lt;li&gt;Node.js is also convenient for writing command-line utilities that automate tasks such as:

&lt;ul&gt;
&lt;li&gt;Reading and writing files&lt;/li&gt;
&lt;li&gt;Renaming or organizing files&lt;/li&gt;
&lt;li&gt;Processing CSV or JSON data&lt;/li&gt;
&lt;li&gt;Running build scripts similar to &lt;em&gt;python&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Automating deployments&lt;/li&gt;
&lt;li&gt;Call REST APIs (fetch, http, https)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To be continued...&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Things about sorting you need to know</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:29:06 +0000</pubDate>
      <link>https://dev.to/d32ssv/things-about-sorting-you-need-to-know-4a18</link>
      <guid>https://dev.to/d32ssv/things-about-sorting-you-need-to-know-4a18</guid>
      <description>&lt;p&gt;We've all come across various sorting algorithms like bubble sort, merge sort etc whether being new or experienced in programming but sometimes the default sorting is not enough &amp;amp; requires a little tune up, then you need to implement a custom comparison.&lt;/p&gt;

&lt;p&gt;This post explores a fundamental property of comparator functions. You'll encounter it whenever you write a custom comparator in JavaScript, especially after discovering that Array.prototype.sort() sorts values lexicographically by default or while solving coding problems on LeetCode for priority queues.&lt;br&gt;
For instance,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//lexicographic comparison converts the values to strings and&lt;/span&gt;
 &lt;span class="nx"&gt;then&lt;/span&gt; &lt;span class="nx"&gt;compares&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// [10, 2, 5] &lt;/span&gt;

&lt;span class="c1"&gt;//comparator here uses numerical value&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// [2, 5, 10]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Rule Every Comparator Follows
&lt;/h2&gt;

&lt;p&gt;This is mainly about the underlying comparison principle used when comparing two values and deciding which one to place first and which one to place later.&lt;/p&gt;

&lt;p&gt;The comparator decides the relative placement of two values, by &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;using a '&lt;em&gt;a certain custom comparison logic&lt;/em&gt;' and &lt;/li&gt;
&lt;li&gt;communicating that ordering by returning a negative number, zero, or a positive number.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A comparator returns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a negative value if a should come &lt;strong&gt;before&lt;/strong&gt; b&lt;/li&gt;
&lt;li&gt;zero if they are considered equal&lt;/li&gt;
&lt;li&gt;positive value if a should come &lt;strong&gt;after&lt;/strong&gt; b&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Sorting algorithms do not generally subtract values.&lt;/em&gt; However,&lt;br&gt;
&lt;code&gt;&lt;br&gt;
Using a - b is simply a convenient implementation for numbers because subtraction naturally produces the required sign.&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
For an array of objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;age:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;54&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;height:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;173&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;age:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;height:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Comparison based on age
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Comparison based on height
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the above comparison can be done like this as well:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(a, b) =&amp;gt; a.height - b.height;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This works because if &lt;code&gt;a.height &amp;lt; b.height, the subtraction produces a negative result&lt;/code&gt;, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;indicating that a should be placed before b. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Likewise, &lt;code&gt;a positive result places a **after** b&lt;/code&gt;, and &lt;br&gt;
&lt;code&gt;0 means the two values are considered equal for sorting purposes&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>Thoughts on implementing a custom Priority Queue in TS</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Tue, 16 Jun 2026 07:48:03 +0000</pubDate>
      <link>https://dev.to/d32ssv/thoughts-on-implementing-a-custom-priority-queue-in-ts-1e2k</link>
      <guid>https://dev.to/d32ssv/thoughts-on-implementing-a-custom-priority-queue-in-ts-1e2k</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/last-stone-weight/" rel="noopener noreferrer"&gt;LC 1046&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My two cents:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Each push and pop requires a rearrangement of the existing elements, it's almost like the priority queue is a living organism which evolves / devolves it self to maintain the order of the elements.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Swap, BubbleUp, &amp;amp; BubbleDown are the methods doing the main lifting. Here, swap is the simple swap operation&lt;br&gt;
&lt;code&gt;const temp: T = this.heap[i];&lt;br&gt;
this.heap[i] = this.heap[j];&lt;br&gt;
this.heap[j] = temp&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;this.compare&lt;/code&gt; dependency injection is the soul of the code here. It is the same deciding factor which is used in &lt;a href="https://dev.to/d32ssv/things-about-sorting-you-need-to-know-4a18"&gt;sorting&lt;/a&gt; elements in an array. &lt;code&gt;number &amp;lt; 0&lt;/code&gt;, &lt;code&gt;number = 0&lt;/code&gt; &amp;amp; &lt;code&gt;number &amp;gt; 0&lt;/code&gt; &lt;br&gt;
where number is the result of a-b or b-a.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;bubbleUp and bubbleDown ensure the rearrangement which is required to maintain the order of the elements,&lt;/em&gt; &lt;br&gt;
bubbleDown refers to the Pop operation, and bubbleUp refers to the push operation. This is because how they are implemented in the custom heap inside the CustomPriorityQueue class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Complexity
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Time complexity:
O(N * log(N)); 
explanation : Push, Pop has log(N) and Stones array traversal has N.&lt;/li&gt;
&lt;li&gt;Space complexity: 
O(N) for additional priority queue.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;lastStoneWeight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stones&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PQ&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;CustomPriorityQueue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;stones&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(PQ);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PQ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CustomPriorityQueue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="na"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="na"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;compare&lt;/span&gt;
        &lt;span class="c1"&gt;// this.heap = [];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;j&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bubbleUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;bubbleUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="na"&gt;parentIndex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;parentIndex&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parentIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;parentIndex&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bubbleDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;bubbleDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="na"&gt;leftChildIndex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="na"&gt;rightChildIndex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="na"&gt;indexOfSmallestOrLargest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leftChildIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;leftChildIndex&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;leftChildIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rightChildIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rightChildIndex&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rightChildIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;indexOfSmallestOrLargest&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dsa</category>
      <category>ts</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>What happened when I used the Web Speech API?</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Sun, 12 Oct 2025 11:16:55 +0000</pubDate>
      <link>https://dev.to/d32ssv/what-happened-when-i-used-the-web-speech-api-3jjl</link>
      <guid>https://dev.to/d32ssv/what-happened-when-i-used-the-web-speech-api-3jjl</guid>
      <description>&lt;h2&gt;
  
  
  Behind the scene : The Goal...
&lt;/h2&gt;

&lt;p&gt;I wanted to make a web app for my personal use, which involved &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continuously listen to the user’s speech&lt;/li&gt;
&lt;li&gt;Convert it to text in real-time&lt;/li&gt;
&lt;li&gt;Track the frequency of a specific word (e.g., “Shiv”)&lt;/li&gt;
&lt;li&gt;Display that count on screen and store it locally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple idea. Surprisingly tricky to implement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Expectations vs Reality
&lt;/h3&gt;

&lt;p&gt;The app technically worked using the Web Speech API. It listened, transcribed, and returned results. However, instead of processing each word as it was spoken, it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Listened to full chunks of speech&lt;/li&gt;
&lt;li&gt;Waited for pauses or silence&lt;/li&gt;
&lt;li&gt;Then returned a batch of words all at once&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even with &lt;code&gt;{ continuous: true }&lt;/code&gt;, the speech recognition didn’t behave the way I expected — no real-time, word-by-word updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Findings
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;It is not reliable for low-latency, high-frequency word detection&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;The Web Speech API buffers audio and processes it after short silences. &lt;/li&gt;
&lt;li&gt;It often fails to keep up with fast, continuous speech.&lt;/li&gt;
&lt;li&gt;Repeating the same word (e.g., "Shiv Shiv Shiv Shiv Shiv") often causes the recognizer to combine or ignore duplicates.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Stream Audio → Transcribe → Return Text&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Use a Cloud-Based Speech-to-Text API&lt;/li&gt;
&lt;li&gt;Run an OpenAI whisper STT model on a server locally.&lt;/li&gt;
&lt;li&gt;Stream the voice data using a websocket to the backend.&lt;/li&gt;
&lt;li&gt;Backend transcribes the speech and sends reponse to the browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Result
&lt;/h3&gt;

&lt;p&gt;Understood the limitations of the web speech api and will work on the project with a fresh start.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>Install node js ubuntu</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Sun, 08 Oct 2023 10:30:29 +0000</pubDate>
      <link>https://dev.to/d32ssv/install-node-js-ubuntu-153</link>
      <guid>https://dev.to/d32ssv/install-node-js-ubuntu-153</guid>
      <description>&lt;p&gt;This is a guide to installing node js on a Ubuntu machine. You can keep multiple versions of node simultaneously and switch between them as per the requirement.&lt;br&gt;
Follow the below steps for installation : &lt;/p&gt;

&lt;p&gt;Run the command ensuring your system is up to date.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install the latest stable version, run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo snap install node --classic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or  Visit the &lt;a href="https://snapcraft.io/node" rel="noopener noreferrer"&gt;Official Snap website&lt;/a&gt; to see the list of available versions.&lt;/p&gt;

&lt;p&gt;To confirm the installed version of node, run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you wish to have more than one version of node installed. Run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install v19.9.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;strong&gt;v19.9.0&lt;/strong&gt; is used as an example and can be replaced by a version of your choice!&lt;/p&gt;

&lt;p&gt;To see all the available versions, use the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm list-remote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see the list of node versions that are installed on your pc, run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A similar result to the below image will appear.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0j48nhbpzmhdf5h3l0i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0j48nhbpzmhdf5h3l0i.png" alt="list of node" width="444" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To switch between the versions of node, run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm use v19.9.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;strong&gt;v19.9.0&lt;/strong&gt; can be replaced with any other version of node that is installed on the system.&lt;/p&gt;

&lt;p&gt;Thanks for reading this. I hope this was helpful. Any comments or reactions will be wholeheartedly appreciated. &lt;/p&gt;

</description>
      <category>node</category>
      <category>ubuntu</category>
      <category>linux</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Updating Discord on Ubuntu</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Fri, 06 Oct 2023 11:35:06 +0000</pubDate>
      <link>https://dev.to/d32ssv/updating-discord-on-ubuntu-2npd</link>
      <guid>https://dev.to/d32ssv/updating-discord-on-ubuntu-2npd</guid>
      <description>&lt;p&gt;The Discord app does not get updated automatically. Instead, a copy of .deb file is downloaded and the update needs to be installed manually. If you have come across this image &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhd2kh45mw3j58dmrg71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhd2kh45mw3j58dmrg71.png" alt="update alert" width="265" height="288"&gt;&lt;/a&gt;&lt;br&gt;
Follow the below simple easy steps : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download the .deb file&lt;/li&gt;
&lt;li&gt;Go to the downloads folder and open the terminal. This is to ensure that you have changed your present working directory!&lt;/li&gt;
&lt;li&gt;Type the command &lt;code&gt;sudo apt install ./&lt;/code&gt; make sure to include the .deb file after &lt;strong&gt;./&lt;/strong&gt; as shown in the below image.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprk0d7r7dgqoo2v8h4g0.png" alt="command for updating discord using .deb file" width="463" height="36"&gt;
&lt;/li&gt;
&lt;li&gt;Hit Enter and it's done. You should see the below result after Hitting enter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhs2rh7c3qp8da3qj172p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhs2rh7c3qp8da3qj172p.png" alt="Example image after sunccessful update" width="800" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>discord</category>
    </item>
    <item>
      <title>Push, Pop, Shift, Unshift : An Easy way to remember</title>
      <dc:creator>Arun Prakash Pandey</dc:creator>
      <pubDate>Wed, 23 Aug 2023 11:22:23 +0000</pubDate>
      <link>https://dev.to/d32ssv/push-pop-shift-unshift-an-easy-way-to-remember-4jg5</link>
      <guid>https://dev.to/d32ssv/push-pop-shift-unshift-an-easy-way-to-remember-4jg5</guid>
      <description>&lt;p&gt;JavaScript can be confusing in the beginning and this article will help you to easily remember &amp;amp; differentiate between the push(), pop(), shift() and unshift() methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Push() and Unshift()-&amp;gt; 'u' is common
&lt;/h2&gt;

&lt;p&gt;The trick is to observe that the letter &lt;strong&gt;U&lt;/strong&gt; is used to spell push and unshift. Hence, they have similar use cases.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For &lt;strong&gt;Adding one or more elements&lt;/strong&gt; in the array.&lt;/li&gt;
&lt;li&gt;Returns the length of the new array.&lt;/li&gt;
&lt;li&gt;Push() adds elements to the end.&lt;/li&gt;
&lt;li&gt;Unshift() adds elements to the beginning.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Now, you know an easier way to remember &lt;strong&gt;push() and unshift() methods&lt;/strong&gt;.&lt;/em&gt; The pop and shift can be easily associated with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pop() and Shift() -&amp;gt;
&lt;/h2&gt;

&lt;p&gt;The trick is to see that unlike push() and unshift() method (where the letter 'u' is common). Nothing is matching here. So, we can keep the pop and shift method in one group. Their use cases are similar as follows: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Both are used for removing.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Returns the item that was removed.&lt;/li&gt;
&lt;li&gt;Pop() removes from the end.&lt;/li&gt;
&lt;li&gt;Shift() removes from the start of the array.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope this helps you to easily remember the methods and their uses.&lt;br&gt;
Feel free to reach out for feedback (good or bad), or just to connect.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
