<?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: Saharat Paynok</title>
    <description>The latest articles on DEV Community by Saharat Paynok (@regalman).</description>
    <link>https://dev.to/regalman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F336838%2Fd75f9951-d910-442a-99e2-7cbccbd995ad.jpeg</url>
      <title>DEV Community: Saharat Paynok</title>
      <link>https://dev.to/regalman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/regalman"/>
    <language>en</language>
    <item>
      <title>I've been drifting, here is my line in the sand.</title>
      <dc:creator>Saharat Paynok</dc:creator>
      <pubDate>Wed, 24 Sep 2025 00:55:05 +0000</pubDate>
      <link>https://dev.to/regalman/ive-been-drifting-here-is-my-line-in-the-sand-b3a</link>
      <guid>https://dev.to/regalman/ive-been-drifting-here-is-my-line-in-the-sand-b3a</guid>
      <description>&lt;p&gt;I've been distracting myself instead of committing.&lt;br&gt;
I've been busy but not productive.&lt;br&gt;
I've been wasting me potential.&lt;/p&gt;

&lt;p&gt;Here's my line in the sand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I will stop letting Youtube and distractions steal my focus&lt;/li&gt;
&lt;li&gt;I will publish progress every week, no matter how small.&lt;/li&gt;
&lt;li&gt;I will ship one AI side project live in the next 90 days&lt;/li&gt;
&lt;li&gt;I will hold my self accountable by being public about this journey&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post is my first step in burning the old identity&lt;/p&gt;

&lt;p&gt;If you’re reading this — hold me accountable.&lt;br&gt;
Call me out if I disappear.&lt;/p&gt;

&lt;p&gt;New chapter starts today.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>discuss</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Do not use array.sort() Function Without a Compare Function in JavaScript</title>
      <dc:creator>Saharat Paynok</dc:creator>
      <pubDate>Sat, 18 May 2024 15:01:22 +0000</pubDate>
      <link>https://dev.to/regalman/do-not-use-arraysort-function-without-a-compare-function-in-javascript-f97</link>
      <guid>https://dev.to/regalman/do-not-use-arraysort-function-without-a-compare-function-in-javascript-f97</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6guc90m0mbxkjsn7o8mr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6guc90m0mbxkjsn7o8mr.png" alt="Image description" width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might need to sort their elements when working with arrays in JavaScript. The sort() function is commonly used for this purpose. However, there’s an important caveat: if you’re dealing with an array of numbers, using sort() without a compare function can yield unexpected outcomes.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Default Behavior of sort()
&lt;/h1&gt;

&lt;p&gt;By default, the sort() function treats elements as strings and compares them based on their UTF-16 code units order. This behavior works well for sorting strings alphabetically, but it falls short when sorting numbers&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Sorting Strings
&lt;/h3&gt;

&lt;p&gt;Let’s say we have an array of animal names:&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;animals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Horse&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tiger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lion&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;animals&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;// Result: ["Cat", "Horse", "Lion", "Tiger"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The strings are sorted alphabetically, which is what we expect.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Sorting Numbers
&lt;/h3&gt;

&lt;p&gt;Now, consider an array of numbers:&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&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;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;numbers&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, 11, 12, 13, 14, 15, 16]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait, what happened? The numbers are sorted as strings! The reason is that the default comparison treats them as such.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Solution: Using a Compare Function
&lt;/h1&gt;

&lt;p&gt;You must provide a compare function to sort numbers (or any other data type) properly. This callback function defines an alternative sorting order. It takes two arguments (often referred to as a and b) and returns either a positive, negative, or zero.&lt;/p&gt;

&lt;p&gt;Here’s how you can create a simple compare function for sorting numbers:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;compare&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function:&lt;/p&gt;

&lt;p&gt;If a is greater than b, it returns a positive value.&lt;br&gt;
If a equals b, it returns zero.&lt;br&gt;
If a is less than b, it returns a negative value.&lt;br&gt;
Now, let’s sort our array of numbers using this compare function:&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="nx"&gt;numbers&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;compare&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Result: [10, 11, 12, 13, 14, 15, 16]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect! The numbers are now sorted correctly.&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Remember that when sorting arrays in JavaScript, especially with numbers, always use a compare function. It ensures predictable and accurate sorting behavior. Don’t rely on the default string-based sorting; take control by providing your comparison logic.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;




&lt;p&gt;Feel free to customize this article further or add any additional insights you’d like to share. If you have more requests or questions, feel free to ask! 😊👍&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to check if the character is alphanumeric in GO</title>
      <dc:creator>Saharat Paynok</dc:creator>
      <pubDate>Thu, 16 May 2024 17:50:11 +0000</pubDate>
      <link>https://dev.to/regalman/how-to-check-if-the-character-is-alphanumeric-in-go-4837</link>
      <guid>https://dev.to/regalman/how-to-check-if-the-character-is-alphanumeric-in-go-4837</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Characters in Go as Bytes
&lt;/h2&gt;

&lt;p&gt;In Go, a string is equivalent to a slice of bytes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Solution: Checking if a Character is Alphanumeric
&lt;/h2&gt;

&lt;p&gt;To determine whether a character is alphanumeric (i.e., a letter or a digit), you can create a function that checks the byte value of the character. &lt;/p&gt;

&lt;p&gt;Here’s an example implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;isAlphaNumeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Check if the byte value falls within the range of alphanumeric characters&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="sc"&gt;'z'&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="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="sc"&gt;'A'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="sc"&gt;'Z'&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="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="sc"&gt;'0'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="sc"&gt;'9'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;isAlphaNumeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// true&lt;/span&gt;

    &lt;span class="n"&gt;isAlphaNumeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// true (digits are also considered alphanumeric)&lt;/span&gt;

    &lt;span class="n"&gt;isAlphaNumeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'#'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;In the isAlphaNumeric function:&lt;br&gt;
We check if the byte value c corresponds to a lowercase letter ('a' to 'z'), an uppercase letter ('A' to 'Z'), or a digit ('0' to '9').&lt;br&gt;
If the condition is met, we return true; otherwise, we return false.&lt;/p&gt;




&lt;p&gt;Let me know if you have an alternative solution or learned something from this post.&lt;/p&gt;

</description>
      <category>go</category>
      <category>howto</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
