<?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: Joshua Eirman</title>
    <description>The latest articles on DEV Community by Joshua Eirman (@joshuaeirm).</description>
    <link>https://dev.to/joshuaeirm</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%2F3332347%2Fa9b33b64-e28f-4bc5-a307-f31b80123232.jpg</url>
      <title>DEV Community: Joshua Eirman</title>
      <link>https://dev.to/joshuaeirm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joshuaeirm"/>
    <language>en</language>
    <item>
      <title>Problem understanding shiftRight function.</title>
      <dc:creator>Joshua Eirman</dc:creator>
      <pubDate>Mon, 07 Jul 2025 17:16:39 +0000</pubDate>
      <link>https://dev.to/joshuaeirm/problem-understanding-shiftright-function-1ie8</link>
      <guid>https://dev.to/joshuaeirm/problem-understanding-shiftright-function-1ie8</guid>
      <description>&lt;p&gt;Hello, while writing with JavaScript, I encountered the following shiftRight() function.  The final section clears the last character with a dash.  This is because it is overwritten.  I am not understanding why this is needed, I tried to research but my efforts were unpromising.  Thanks!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// === Shift all characters one space to the right (after insertion) ===
function shiftRight(row, col) {
  // Flattened index of the insertion point
  // Shift everything from this point to the right by 1
  for (let i = ROWS * COLS - 2; i &amp;gt;= row * COLS + col; i--) {
    const from = i;       // Current character index
    const to = i + 1;     // Destination index (1 cell to the right)

    // Convert 1D index to 2D row and column
    const fr = Math.floor(from / COLS); // From row
    const fc = from % COLS;             // From col
    const tr = Math.floor(to / COLS);   // To row
    const tc = to % COLS;               // To col

    // Move character to the right
    grid[tr][tc] = grid[fr][fc];
  }

  // Clear the last cell in the grid
  const lastIndex = ROWS * COLS - 1;         // Final 1D index of the grid
  const lastR = Math.floor(lastIndex / COLS); // Last row
  const lastC = lastIndex % COLS;             // Last col
  grid[lastR][lastC] = DASH;
}

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

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
