<?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>Forem: Jackinthesquare</title>
    <description>The latest articles on Forem by Jackinthesquare (@jackinthesquare).</description>
    <link>https://forem.com/jackinthesquare</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%2F846321%2F2e6f45db-e973-422a-9523-70ea23abdcc5.png</url>
      <title>Forem: Jackinthesquare</title>
      <link>https://forem.com/jackinthesquare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jackinthesquare"/>
    <language>en</language>
    <item>
      <title>React Router</title>
      <dc:creator>Jackinthesquare</dc:creator>
      <pubDate>Mon, 25 Apr 2022 03:05:22 +0000</pubDate>
      <link>https://forem.com/jackinthesquare/react-router-47kb</link>
      <guid>https://forem.com/jackinthesquare/react-router-47kb</guid>
      <description>&lt;p&gt;Navigation is important in single page applications. One of the important libraries in React is the router library that allows us to switch between components in our application.&lt;/p&gt;

&lt;p&gt;First thing first, I need to install the router dom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install react-router-dom@5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After, I need to import BrowserRouter to index.js:&lt;br&gt;
&lt;code&gt;import { BrowserRouter } from 'react-router-dom';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If a module error about react router dom not found, I will need to install:&lt;br&gt;
&lt;code&gt;npm install react-router-dom --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then I need to wrap up the root component with a BrowserRouter tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReactDOM.render(
  &amp;lt;BrowserRouter&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/BrowserRouter&amp;gt;,
  document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, in the root component, I will import:&lt;br&gt;
&lt;code&gt;import { Switch, Route } from "react-router-dom"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then I can setup the root component after the return():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;NavBar onChangePage={setPage} /&amp;gt;
      &amp;lt;Switch&amp;gt;
        &amp;lt;Route exact path="/"&amp;gt;
          &amp;lt;Home /&amp;gt;
        &amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/about"&amp;gt;
          &amp;lt;About /&amp;gt;
        &amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/project"&amp;gt;
          &amp;lt;Project /&amp;gt;
        &amp;lt;/Route&amp;gt;
        &amp;lt;Route path="*"&amp;gt;
          &amp;lt;h1&amp;gt;404 not found&amp;lt;/h1&amp;gt;
        &amp;lt;/Route&amp;gt;
      &amp;lt;/Switch&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "exact" in exact path makes it so that the path needs to be exactly what it is in order for it to switch pages. Notice how it is only in the home "/" part. &lt;code&gt;&amp;lt;Routh path="*"&amp;gt;&lt;/code&gt; is a wildcard path.&lt;/p&gt;

&lt;p&gt;Next, I need to setup the Nav component with an import:&lt;br&gt;
&lt;code&gt;import { Link } from "react-router-dom"&lt;/code&gt;&lt;br&gt;
Under the hood, Link performs such as with the "a" anchor tag and onClick event listener to trigger a state change on the path route. &lt;/p&gt;

&lt;p&gt;Then there is also:&lt;br&gt;
&lt;code&gt;import { NavLink } from "react-router-dom"&lt;/code&gt; &lt;br&gt;
and with NavLink I can also set up css to indicate a link change if it is active:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nav a.active {
  background-color: aquamarine;
  color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The return setup in the Nav component follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; return (
        &amp;lt;nav&amp;gt; 
            &amp;lt;NavLink exact to="/"&amp;gt;Home &amp;lt;/NavLink&amp;gt;
            &amp;lt;NavLink to="/about"&amp;gt;About &amp;lt;/NavLink&amp;gt;
            &amp;lt;NavLink to="/project"&amp;gt;Project &amp;lt;/NavLink&amp;gt;
        &amp;lt;/nav&amp;gt;
    )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and voila! a working Navigation bar.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Oh, the things I would do to an Array</title>
      <dc:creator>Jackinthesquare</dc:creator>
      <pubDate>Wed, 13 Apr 2022 01:43:03 +0000</pubDate>
      <link>https://forem.com/jackinthesquare/oh-the-things-i-would-do-to-an-array-4c75</link>
      <guid>https://forem.com/jackinthesquare/oh-the-things-i-would-do-to-an-array-4c75</guid>
      <description>&lt;p&gt;In JavaScript, an array is an object. More often than not, we will be provided with an array of elements or an object that consists of an array of elements that we need to extract and/or  modify and this is where some of these methods make our lives easier:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;array.mapping() / array.forEach()&lt;/li&gt;
&lt;li&gt;array.filter()&lt;/li&gt;
&lt;li&gt;array.reduce()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Arr Captain&lt;/strong&gt;&lt;br&gt;
Why do we use arrays? Arrays were most likely created for us to have an easy way to store a collection of similar data, (It's possible to have mixed datatypes but not recommended - that's why we have objects!) so that we don't need to declare a ton of variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1,3,3,7]; //same datatype of integers
const array2 = [1,"3",3,7]; //legal but not recommended
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;vs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const variable1 = 1;
const variable2 = 3;
const variable3 = 3;
const variable4 = 7;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array Iterating&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More often, you may need to extract information from an array and usually all of it and that's where array.map() and array.forEach() comes in. These functions iterate over every element and returns a callback function. The only &lt;strong&gt;difference&lt;/strong&gt; is map returns a new Array while forEach only iterates over the elements. So what that means is that if you do not need to modify an array, use forEach instead of map.&lt;/p&gt;

&lt;p&gt;Here is an example. Recently I had to fetch data from an API database but the array of moves contained a dash "-" and I didn't want that since it obstructed the way my project functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const moves = ["karate-chop","double-slap", "comet-punch", "mega-punch"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the array.map() method to iterate over every move to replace the dash with a space and assigned the result to return to a new array, newMoves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newMoves = moves.map(move =&amp;gt; move.replace(/[^a-zA-Z ]/g, " "))
console.log(moves)
console.log(newMoves)
// (4) ['karate-chop', 'double-slap', 'comet-punch', 'mega-punch'] // (4) ['karate chop', 'double slap', 'comet punch', 'mega punch']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;whereas&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newMoves = moves.forEach(move =&amp;gt; move.replace(/[^a-zA-Z ]/g, " "))
console.log(moves)
console.log(newMoves)
// (4) ['karate-chop', 'double-slap', 'comet-punch', 'mega-punch'] // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are ways around that to use forEach but it would be more work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array Filtering&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter&lt;/a&gt;&lt;br&gt;
Filtering an array is equally as important since sometimes you may not want to use everything from the array. The array.filter() method, creates a new array returning the condition you set in the callback function. The example in the documentary link is pretty self explanatory but it is also possible to use the ! - not operator to return an array to exclude element(s):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ids = [1, 2, 3, 4, 5]
const newIds = ids.filter(id =&amp;gt; id !== 2)
console.log(ids)
console.log(newIds)
//(5) [1, 2, 3, 4, 5]
//(4) [1, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array Reducing&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce&lt;/a&gt;&lt;br&gt;
Less often, we may need to break down an array and return it with one value. Remember, arrays are objects so we may have a list of numbers in an object and we want to return a total number. The parameters that the array.reduce() function takes are a callback function and an optional initialization value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [101, 4, 6, 20, 9];

const reduceFunction = (total, num) =&amp;gt; {
  return total - num;
}

console.log(numbers.reduce(reduceFunction))
// 62

console.log(numbers.reduce(reduceFunction, 100))
// -40

console.log(numbers.reduce(reduceFunction, 200))
// 60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am sure there are many other array manipulation methods out there but these will be the most common, general ones that will be used and it's important to learn how to use them to improve QOL!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My Journey as a student</title>
      <dc:creator>Jackinthesquare</dc:creator>
      <pubDate>Tue, 12 Apr 2022 17:42:35 +0000</pubDate>
      <link>https://forem.com/jackinthesquare/my-journey-1813</link>
      <guid>https://forem.com/jackinthesquare/my-journey-1813</guid>
      <description>&lt;p&gt;April 12 2022&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;br&gt;
Before committing to the path on becoming a software engineer, I was studying electrical engineering. Then Covid-19 hit and during that downtime, I was introduced to the vast digital world where "bots" run amok and certain scams received world recognition &lt;em&gt;cough&lt;/em&gt; Crypto-currencies and especially Nfts &lt;em&gt;cough&lt;/em&gt;. During these last 2 years, I've learned more about how a certain aspect of the world, functions and computer science has definitely impressed me with how it has advanced since the dotcom age.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prelude to coding&lt;/strong&gt;&lt;br&gt;
Anyone can code. Success in coding requires a strong mental mindset to follow logic. It is important to understand that coding is a tool for humans to &lt;em&gt;&lt;strong&gt;communicate&lt;/strong&gt;&lt;/em&gt; with machines but the tool is also created by humans...hmm makes you think. The syntaxes for each language is comparable to the jargons that are used by lawyers, doctors, etc. We just need to accept it! (because the humans that created the coding languages made it that way)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cout &amp;lt;&amp;lt; "Hello";&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;console.log("Hello")&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;print("Hello")&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Above, I have listed 4 different coding languages to outputting the string-text "Hello World!" Learning that is comparable to learning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hello&lt;/li&gt;
&lt;li&gt;你好 (Ni hao)&lt;/li&gt;
&lt;li&gt;Hola&lt;/li&gt;
&lt;li&gt;Bonjour&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think about it - It's called a coding "language" for a reason! If you are able to understand what I have wrote so far, you can pick up a coding language too!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making enemies&lt;/strong&gt;&lt;br&gt;
A coder can always use a second pair of eyes no matter how good he/she is and that is why we need to write in a clean way and use easy-to-understand variables. If others won't hate you, you might hate yourself for wasting time understanding the logic when trying to reference the code months/years later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is My Blog&lt;/strong&gt;&lt;br&gt;
This is my personal blog that will reflect my journey starting as a software developer. I will update it as I come across methods, techniques and or syntaxes that will make my code better. The reason I said it's personal is because it is something I will want to look back one day and be able to see my capacity at the time and reflect on my growth.&lt;/p&gt;

&lt;p&gt;*disclaimer: At this time of writing, crypto and nfts have no logistic functions other than an exchange market.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
