<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gatsby Starter Blog RSS Feed]]></title><description><![CDATA[A blog detailing Zach Stone's journey from English teacher to software engineer. ]]></description><link>https://zach-stone.netlify.app</link><generator>GatsbyJS</generator><lastBuildDate>Thu, 05 Dec 2024 10:54:49 GMT</lastBuildDate><item><title><![CDATA[Understanding Object References and Creating Copies of Objects in JavaScript]]></title><description><![CDATA[English / 日本語　 The Code Let’s first examine the given JavaScript code: What is the outcome? … [1, 2, 3, 4], [1, 2, 3, 4] ! Outcome…]]></description><link>https://zach-stone.netlify.app/Understanding Array References and Creating Copies in JavaScript/</link><guid isPermaLink="false">https://zach-stone.netlify.app/Understanding Array References and Creating Copies in JavaScript/</guid><pubDate>Sun, 02 Apr 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h4&gt;English / 日本語　&lt;/h4&gt;
&lt;hr&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;p&gt;Let’s first examine the given JavaScript code:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = arr1;

arr2.push(4);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;What is the outcome?&lt;/h2&gt;
&lt;h3&gt;…&lt;/h3&gt;
&lt;h2&gt;[1, 2, 3, 4], [1, 2, 3, 4] !&lt;/h2&gt;
&lt;h2&gt;Outcome Explanation&lt;/h2&gt;
&lt;p&gt;The outcome is [1, 2, 3, 4], [1, 2, 3, 4]. To understand why this is the case, we need to break down the code step by step:&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This line creates a constant array arr1 containing the elements 1, 2, and 3.&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;const arr2 = arr1&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This line creates a new constant array arr2 and assigns it the value of arr1. However, in Javascript Objects are passed by reference so arr2 is not assigned a new array with the same values; instead, it is assigned a reference to arr1. This means both arr1 and arr2 point to the same memory location.&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;arr2.push(4)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This line pushes the element 4 to the arr2 array. Since arr2 is just a reference to arr1, the push operation also affects arr1. As a result, both arrays now contain the elements [1, 2, 3, 4].&lt;/p&gt;
&lt;h2&gt;Making a Copy of an Array without Reference&lt;/h2&gt;
&lt;p&gt;To prevent modifying the original array when updating a copy, we can create a new array without a reference to the original array. There are several ways to achieve this:&lt;/p&gt;
&lt;h3&gt;Using the spread operator:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = [...arr1];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Using Array.from()&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = Array.from(arr1);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Using slice() method:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = arr1.slice();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Using JSON.parse() and JSON.stringify():&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = JSON.parse(JSON.stringify(arr1));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;When assigning one array to another, it’s important to be aware that JavaScript assigns references instead of creating a new array with the same values.&lt;/p&gt;
&lt;p&gt;To make a copy of an array without referencing the original, several methods can be used, including the spread operator, Array.from(), the slice() method, and JSON.parse() with JSON.stringify() and more.&lt;/p&gt;
&lt;p&gt;However, it’s important to note that each of these methods has its limitations and potential pitfalls. Maybe we can talk about that in another post.&lt;/p&gt;
&lt;hr&gt;
&lt;h5&gt;*CHATGPT で訳した&lt;/h5&gt;
&lt;p&gt;最初に、与えられた JavaScript コードを見てみましょう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3]
const arr2 = arr1

arr2.push(4)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;結果は何ですか？&lt;/h2&gt;
&lt;h3&gt;…&lt;/h3&gt;
&lt;h2&gt;[1, 2, 3, 4], [1, 2, 3, 4] !&lt;/h2&gt;
&lt;h2&gt;結果の説明&lt;/h2&gt;
&lt;p&gt;このコードの結果は [1, 2, 3, 4], [1, 2, 3, 4] です。なぜこのような結果になるかを理解するために、コードをステップごとに見ていきましょう。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;この行は、要素 1、2、3 を含む定数配列 arr1 を作成します。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;const arr2 = arr1&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;この行は、新しい定数配列 arr2 を作成し、arr1 の値を代入します。しかし、JavaScript ではオブジェクトは参照によって作成されるため、arr2 には同じ値を持つ新しい配列が割り当てられるのではなく、arr1 への参照が割り当てられます。これは、arr1 と arr2 の両方が同じメモリ領域を指していることを意味します。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;arr2.push(4)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;この行は、要素 4 を arr2 配列にプッシュします。arr2 は arr1 への参照であるため、プッシュ操作は arr1 にも影響します。結果として、両方の配列には要素 [1, 2, 3, 4] が含まれます。&lt;/p&gt;
&lt;h2&gt;参照なしで配列のコピーを作成する&lt;/h2&gt;
&lt;p&gt;コピーを更新する際に元の配列を変更しないようにするために、元の配列への参照なしで新しい配列を作成することができます。これを実現する方法はいくつかあります。&lt;/p&gt;
&lt;h3&gt;スプレッド演算子を使用する:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = [...arr1];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Array.from()を使用する:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = Array.from(arr1);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;slice()メソッドを使用する:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = arr1.slice();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;JSON.parse()と JSON.stringify()を使用する:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const arr1 = [1, 2, 3];
const arr2 = JSON.parse(JSON.stringify(arr1));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;結論&lt;/h2&gt;
&lt;p&gt;まとめると、JavaScript がオブジェクトの参照を扱う方法とオブジェクトのコピーを作成する方法を理解することは、コードで意図しない副作用を回避するために非常に重要です。配列を別の配列に割り当てる際には、JavaScript が同じ値を持つ新しい配列を作成するのではなく、参照を割り当てることを意識することが重要です。&lt;/p&gt;
&lt;p&gt;元の配列を参照せずに配列のコピーを作成するためには、スプレッド演算子、Array.from()、slice()メソッド、および JSON.parse()と JSON.stringify()など、いくつかの方法があります。&lt;/p&gt;
&lt;p&gt;ただし、これらの方法にはそれぞれ制限と潜在的な注意点があることに注意する必要があります。また、他のポストで書こうと思っています。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[My Anime Collection Walkthrough]]></title><description><![CDATA[If you would rather have a video walkthrough of the codebase, you can watch it here: https://youtu.be/YVlIq4clxxk Client Public Standard…]]></description><link>https://zach-stone.netlify.app/my_anime_collection/</link><guid isPermaLink="false">https://zach-stone.netlify.app/my_anime_collection/</guid><pubDate>Sun, 24 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you would rather have a video walkthrough of the codebase, you can watch&lt;/p&gt;
&lt;p&gt;it here: &lt;a href=&quot;https://youtu.be/YVlIq4clxxk&quot;&gt;https://youtu.be/YVlIq4clxxk&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Client&lt;/strong&gt;&lt;/h2&gt;
&lt;h3&gt;Public&lt;/h3&gt;
&lt;p&gt;Standard React App setup. The index.html file has a bunch of meta info for different social media, and a thumbnail image is used for the meta info.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;
   &amp;lt;meta name=&quot;Twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;
    &amp;lt;meta name=&quot;Twitter:title&quot; content=&quot;My Anime Collection&quot; /&gt;
    &amp;lt;meta
      name=&quot;Twitter:description&quot;
      content=&quot;An anime tracker application made by Zach Stone.&quot;
    /&gt;
    &amp;lt;meta name=&quot;twitter:image&quot; content=&quot;%PUBLIC_URL%/thumb1.png&quot; /&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;src&lt;/h3&gt;
&lt;p&gt;This is where the front-end app is located and is divided into parts.&lt;/p&gt;
&lt;h3&gt;assets&lt;/h3&gt;
&lt;p&gt;a folder containing all of the global CSS and images for the app&lt;/p&gt;
&lt;h5&gt;CSS&lt;/h5&gt;
&lt;p&gt;The CSS files are split into separate files and then imported into the index.css file.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;@import &quot;dark.css&quot;;
@import &quot;light.css&quot;;
@import &quot;text.css&quot;;
@import &quot;forms.css&quot;;
@import &quot;buttons.css&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The entire app uses light and dark themes, which can be changed on the profile page. The preference is saved in the user schema, so if the user logs onto a new device, it will still be their preferred color theme.&lt;/p&gt;
&lt;p&gt;example&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;[data-theme=&quot;dark&quot;] {
  /* colors */
  --yellow-light: #cdbf42;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;images&lt;/h4&gt;
&lt;p&gt;This folder contains all of the images in the app. They are all in webp format to reduce file size, and some are organized into separate folders, such as the sample anime cards and testimonial headshots on the landing page.&lt;/p&gt;
&lt;h4&gt;audio&lt;/h4&gt;
&lt;p&gt;This contains the audio for the app. the audio is saved in the global state so it can be started and stopped from the landing or on any page once the user has logged in. I plan to create something more akin to a playlist-like experience in a future update.&lt;/p&gt;
&lt;h4&gt;Components&lt;/h4&gt;
&lt;p&gt;The components are organized according to atomic design principles. I also used styled-components to keep the CSS clean and out of the global CSS files when only used in single components.&lt;/p&gt;
&lt;p&gt;Here are a few examples&lt;/p&gt;
&lt;h5&gt;Atoms&lt;/h5&gt;
&lt;p&gt;Logo Components&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import logo from &quot;../../assets/images/logo.svg&quot;;

const Logo = () =&gt; {
  return &amp;lt;img src={logo} alt=&quot;My Anime Collection&quot; className=&quot;logo&quot; /&gt;;
};

export default Logo;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Molecules&lt;/h4&gt;
&lt;p&gt;Music and language changer component&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import america from &quot;../../assets/images/america.webp&quot;;
import IconButton from &quot;@mui/material/IconButton&quot;;
import japan from &quot;../../assets/images/japan.webp&quot;;
import Box from &quot;@mui/material/Box&quot;;
import { useAppContext } from &quot;../../context/appContext&quot;;
import { useTranslation } from &quot;react-i18next&quot;;
import styled from &quot;styled-components&quot;;

//icons
import { PlayCircle, PauseCircle } from &quot;@mui/icons-material&quot;;

const MusicAndFlag = () =&gt; {
  const { changeSiteLanguage, playOrPauseAudio, isAudioPlaying } =
    useAppContext();
  const { i18n } = useTranslation();

  return (
    &amp;lt;Wrapper&gt;
      {i18n.language === &quot;en&quot; ? (
        &amp;lt;Box className=&quot;full-flag-div flag-div-holder&quot;&gt;
          &amp;lt;IconButton
            color=&quot;warning&quot;
            size=&quot;medium&quot;
            variant=&quot;contained&quot;
            aria-label=&quot;play/ pause&quot;
            onClick={(e) =&gt; playOrPauseAudio(e)}
          &gt;
            {isAudioPlaying ? (
              &amp;lt;PauseCircle fontSize=&quot;large&quot; /&gt;
            ) : (
              &amp;lt;PlayCircle fontSize=&quot;large&quot; /&gt;
            )}
          &amp;lt;/IconButton&gt;
          &amp;lt;div className=&quot;flag-div nav-button&quot;&gt;
            &amp;lt;img
              className=&quot;flag&quot;
              src={japan}
              alt=&quot;Japan Flag&quot;
              onClick={() =&gt; changeSiteLanguage(&quot;jp&quot;)}
            /&gt;
          &amp;lt;/div&gt;
        &amp;lt;/Box&gt;
      ) : (
        &amp;lt;Box className=&quot;full-flag-div flag-div-holder&quot;&gt;
          &amp;lt;IconButton
            color=&quot;warning&quot;
            size=&quot;medium&quot;
            variant=&quot;contained&quot;
            aria-label=&quot;play/ pause&quot;
            onClick={(e) =&gt; playOrPauseAudio(e)}
          &gt;
            {isAudioPlaying ? (
              &amp;lt;PauseCircle fontSize=&quot;large&quot; /&gt;
            ) : (
              &amp;lt;PlayCircle fontSize=&quot;large&quot; /&gt;
            )}
          &amp;lt;/IconButton&gt;
          &amp;lt;div className=&quot;flag-div nav-button&quot;&gt;
            &amp;lt;div className=&quot;flag-div&quot;&gt;
              &amp;lt;div&gt;
                &amp;lt;img
                  className=&quot;flag&quot;
                  src={america}
                  alt=&quot;America Flag&quot;
                  onClick={() =&gt; changeSiteLanguage(&quot;en&quot;)}
                /&gt;
              &amp;lt;/div&gt;
            &amp;lt;/div&gt;
          &amp;lt;/div&gt;
        &amp;lt;/Box&gt;
      )}
    &amp;lt;/Wrapper&gt;
  );
};


export default MusicAndFlag;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Container to show the animes the user has in their collection&lt;/p&gt;
&lt;h3&gt;Organisms&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import { useAppContext } from &quot;../../context/appContext&quot;;
import { useEffect } from &quot;react&quot;;
import Loading from &quot;../Atoms/Loading&quot;;
import Anime from &quot;../Molecules/Anime&quot;;
import styled from &quot;styled-components&quot;;
import PageBtnContainer from &quot;../Molecules/PageBtnContainer&quot;;
import { NavLink } from &quot;react-router-dom&quot;;
import { useTranslation } from &quot;react-i18next&quot;;

const MyAnimesContainer = () =&gt; {
  const { t } = useTranslation();
  const {
    getAnimes,
    animes,
    isLoading,
    page,
    totalAnimes,
    search,
    searchStatus,
    searchType,
    searchStared,
    sort,
    numOfPages,
    currentPlaylist,
  } = useAppContext();
  useEffect(() =&gt; {
    getAnimes();
  }, [
    page,
    search,
    searchStatus,
    searchStared,
    searchType,
    sort,
    currentPlaylist,
  ]);
  if (isLoading) {
    return &amp;lt;Loading center /&gt;;
  }

  if (animes.length === 0) {
    return (
      &amp;lt;Wrapper&gt;
        &amp;lt;h2&gt;
          {t(&quot;my_animes_container.no_anime_message1&quot;)}
          &amp;lt;NavLink to=&quot;/add-anime&quot; className=&quot;btn btn-block btn-hipster&quot;&gt;
            {t(&quot;my_animes_container.no_anime_message2&quot;)}
          &amp;lt;/NavLink&gt;
        &amp;lt;/h2&gt;
      &amp;lt;/Wrapper&gt;
    );
  }

  return (
    &amp;lt;Wrapper&gt;
      &amp;lt;h5&gt;
        {totalAnimes} anime{animes.length &gt; 1 &amp;amp;&amp;amp; &quot;s&quot;} found in playlist
      &amp;lt;/h5&gt;
      &amp;lt;div className=&quot;animes&quot;&gt;
        {animes.map((anime) =&gt; {
          return &amp;lt;Anime key={anime._id} {...anime} type=&quot;delete&quot; /&gt;;
        })}
      &amp;lt;/div&gt;
      &amp;lt;div className=&quot;pageBtnContainer&quot;&gt;
        {numOfPages &gt; 1 &amp;amp;&amp;amp; &amp;lt;PageBtnContainer /&gt;}
      &amp;lt;/div&gt;
    &amp;lt;/Wrapper&gt;
  );
};

const Wrapper = styled.section`
  margin-top: 4rem;
  h2 {
    text-transform: none;
  }
  &amp;amp; &gt; h5 {
    font-weight: 700;
  }
  .animes {
    display: grid;
    grid-template-columns: 1fr;
    row-gap: 2rem;
    color: var(--textColor);
  }

  .pageBtnContainer {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
  }
  @media (min-width: 992px) {
    .animes {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-evenly;
      align-items: center;
    }
  }
`;
export default MyAnimesContainer;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Context&lt;/h3&gt;
&lt;p&gt;The app uses React’s context API. The actions folder continues the action titles imported into the app context and then called in the reducer to update the global state.&lt;/p&gt;
&lt;p&gt;Here is an example of the get animes function, which sends an API request to the backend to get the user’s animes from the MongoDB database and handles any sorting or searching.&lt;/p&gt;
&lt;h5&gt;Actions&lt;/h5&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;export const GET_ANIMES_BEGIN = &quot;GET_ANIMES_BEGIN&quot;;
export const GET_ANIMES_SUCCESS = &quot;GET_ANIMES_SUCCESS&quot;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h5&gt;appContext&lt;/h5&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;  const getAnimes = async () =&gt; {
    const { page, search, searchStatus, searchType, sort, currentPlaylist } =
      state;

    let url = `/animes?page=${page}&amp;amp;status=${searchStatus}&amp;amp;animeType=${searchType}&amp;amp;sort=${sort}&amp;amp;currentPlaylistID=${currentPlaylist.id}`;
    if (search) {
      url = url + `&amp;amp;search=${search}`;
    }
    dispatch({ type: GET_ANIMES_BEGIN });
    try {
      const { data } = await authFetch(URL);
      const { animes, totalAnimes, numOfPages } = data;
      dispatch({
        type: GET_ANIMES_SUCCESS,
        payload: {
          animes,
          totalAnimes,
          numOfPages,
        },
      });
    } catch (error) {
      dispatch({
        type: GET_ANIMES_ERROR,
        payload: { msg: error.response.data.msg },
      });
    }
  };&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;reducer&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;  if (action.type === GET_ANIMES_BEGIN) {
    return { ...state, isLoading: true};
  }
  if (action.type === GET_ANIMES_SUCCESS) {
    return {
      ...state,
      isLoading: false,
      animes: action.payload.animes,
      totalAnimes: action.payload.totalAnimes,
      numOfPages: action.payload.numOfPages,
    };
  }

  if (action.type === GET_ANIMES_ERROR) {
    action.payload.msg
      ? toast.error(action.payload.msg, {
          toastId: &quot;getAnimes&quot;,
        })
      : toast.error(&quot;Something went wrong&quot;, {
          toastId: &quot;getAnimes&quot;,
        });
    return {
      ...state,
      isLoading: false,
    };
  }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;pages&lt;/h3&gt;
&lt;p&gt;The app has a series of pages. Some are protected under a ProtectRoute component&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const ProtectedRoute = ({ children }) =&gt; {
const { user } = useAppContext();
if (!user) {
  return &amp;lt;Navigate to=&quot;/landing&quot; /&gt;;
}
return children;
};
export default ProtectedRoute;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I created a RegisterDemo component that auto-fills some dummy information for the email and password automatically. The process from that point on is the same as Register.js except for one key point. the user has a schema field called “isDemo”. This is true when created as a demo user and will delete the user when the user logs out.&lt;/p&gt;
&lt;h3&gt;translations&lt;/h3&gt;
&lt;p&gt;I used i18n throughout the entire app for translations. It looks like this.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;    &amp;lt;h3&gt;{t(&quot;add_anime.title&quot;)}&amp;lt;/h3&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The English and Japanese translations are split up into JSON files and imported into the i18n file.&lt;/p&gt;
&lt;h3&gt;App.js&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;function App() {
  return (
    &amp;lt;BrowserRouter&gt;
      &amp;lt;Routes&gt;
        &amp;lt;Route
          path=&quot;/&quot;
          element={
            &amp;lt;ProtectedRoute&gt;
              &amp;lt;SharedLayout /&gt;
            &amp;lt;/ProtectedRoute&gt;
          }
        &gt;
          &amp;lt;Route index path=&quot;my-animes&quot; element={&amp;lt;MyAnimes /&gt;} /&gt;
          &amp;lt;Route index path=&quot;edit-playlist&quot; element={&amp;lt;EditPlaylist /&gt;} /&gt;
          &amp;lt;Route index path=&quot;add-anime&quot; element={&amp;lt;AddAnime /&gt;} /&gt;
          &amp;lt;Route index path=&quot;profile&quot; element={&amp;lt;Profile /&gt;} /&gt;
          &amp;lt;Route index path=&quot;top-animes&quot; element={&amp;lt;TopAnimes /&gt;} /&gt;
        &amp;lt;/Route&gt;
        &amp;lt;Route index path=&quot;/register&quot; element={&amp;lt;Register /&gt;} /&gt;
        &amp;lt;Route index path=&quot;/register-demo&quot; element={&amp;lt;RegisterDemo /&gt;} /&gt;
        &amp;lt;Route index path=&quot;/landing&quot; element={&amp;lt;Landing /&gt;} /&gt;
        &amp;lt;Route path=&quot;*&quot; element={&amp;lt;Error /&gt;} /&gt;
      &amp;lt;/Routes&gt;
    &amp;lt;/BrowserRouter&gt;
  );
}

export default App;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The server is built concurrently in the same place as the client. In this case, I use Heroku.&lt;/p&gt;
&lt;h3&gt;controllers&lt;/h3&gt;
&lt;p&gt;This file contains all the controllers to handle the API calls from the client side. Here is an example of the getAnimes get request we made earlier.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const getAnimes = async (req, res) =&gt; {
  const { sort, search, currentPlaylistID } = req.query;

  const queryObject = {
    createdBy: req.user.userId,
    playlistID: currentPlaylistID,
  };
  // add stuff based on condition

  if (search) {
    //i: To match both lower case and upper case pattern in the string.
    queryObject.title = { $regex: search, $options: &quot;i&quot; };
  }

  let result = Anime.find(queryObject);

  if (sort === &quot;latest&quot;) {
    result = result.sort({ creationDate: -1 });
  } else if (sort === &quot;oldest&quot;) {
    result = result.sort({ creationDate: 1 });
  } else if (sort === &quot;rating&quot;) {
    // sort by popularity and then by rating
    result = result.sort({ rating: -1, popularity: -1 });
  } else if (sort === &quot;episodeCount&quot;) {
    result = result.sort({ episodeCount: -1 });
  } else if (sort === &quot;format&quot;) {
    result = result.sort({ format: -1 });
  } else if (sort === &quot;a-z&quot;) {
    result = result.sort({ title: 1 });
  } else if (sort === &quot;z-a&quot;) {
    result = result.sort({ title: -1 });
  } else if (sort === &quot;date added&quot;) {
    result = result.sort({ createdAt: -1 });
  }

  // setup pagination
  const page = Number(req.query.page) || 1;
  const limit = Number(req.query.limit) || 10;
  const skip = (page - 1) * limit;

  result = result.skip(skip).limit(limit);

  const animes = await result;

  const totalAnimes = await Anime.countDocuments(queryObject);
  const numOfPages = Math.ceil(totalAnimes / limit);

  res.status(StatusCodes.OK).json({ animes, totalAnimes, numOfPages });
};&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;db&lt;/h3&gt;
&lt;p&gt;connects to the DB&lt;/p&gt;
&lt;h3&gt;errors&lt;/h3&gt;
&lt;p&gt;Contains all of the custom HTTP error messages that will be sent back to the client to either be displayed in the alert field when logging in or registering or as a toast pop up on the rest of the app.&lt;/p&gt;
&lt;p&gt;I learned most of the error handling from an udemy course I took a while back. I find the setup to work very well once set up. Sending error messages back to the client is something I struggled with before taking that course.&lt;/p&gt;
&lt;h3&gt;middleware&lt;/h3&gt;
&lt;p&gt;contains the auth and error-handler middleware&lt;/p&gt;
&lt;h3&gt;models&lt;/h3&gt;
&lt;p&gt;Contains the models for the mongo DB database.&lt;/p&gt;
&lt;h4&gt;Anime.js&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import mongoose from &quot;mongoose&quot;;

const AnimeSchema = new mongoose.Schema(
  {
    createdBy: {
      type: mongoose.Types.ObjectId,
      ref: &quot;User&quot;,
      required: [true, &quot;Please provide user&quot;],
    },
    creationDate: {
      type: Date,
      required: false,
    },
    id: {
      type: Number,
      required: [true, &quot;Please provide id&quot;],
    },
    title: {
      type: String,
      required: [true, &quot;Please provide title&quot;],
    },
    japanese_title: {
      type: String,
      required: [false, &quot;Please provide japanese title&quot;],
    },
    rating: {
      type: Number,
      required: false,
    },
    format: {
      type: String,
      required: false,
    },
    episodeCount: {
      type: Number,
      required: false,
    },
    synopsis: {
      type: String,
      required: false,
    },
    coverImage: {
      type: String,
      required: false,
    },
    youtubeVideoId: {
      type: String,
      required: false,
    },
    playlistID: {
      type: String,
      required: true,
    },
    isDemoAnime: {
      type: Boolean,
      default: false,
    },
  },
  { timestamps: true }
);

export default mongoose.model(&quot;Anime&quot;, AnimeSchema);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;User.js&lt;/h4&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import mongoose from &quot;mongoose&quot;;
import validator from &quot;validator&quot;;
import bcrypt from &quot;bcryptjs&quot;;
import jwt from &quot;jsonwebtoken&quot;;

const playlist = new mongoose.Schema(
  {
    title: String,
    id: String,
  },
  { timestamps: true }
);

const UserSchema = new mongoose.Schema(
  {
    name: {
      type: String,
      required: [true, &quot;Please provide name&quot;],
      minlength: 3,
      maxlength: 20,
      trim: true,
    },
    email: {
      type: String,
      required: [true, &quot;Please provide email&quot;],
      validate: {
        validator: validator.isEmail,
        message: &quot;Please provide a valid email&quot;,
      },
      unique: true,
    },
    isDemo: {
      type: Boolean,
      default: false,
    },
    password: {
      type: String,
      required: [true, &quot;Please provide password&quot;],
      minlength: 6,
      select: false,
    },
    theme: {
      type: String,
      enum: [&quot;light&quot;, &quot;dark&quot;],
      default: &quot;dark&quot;,
    },

    language: {
      type: String,
      enum: [&quot;en&quot;, &quot;jp&quot;],
      default: &quot;en&quot;,
    },

    playlists: {
      type: [playlist],
      default: [
        {
          title: &quot;Default&quot;,
          id: &quot;0&quot;,
        },
      ],
    },
  },
  { timestamps: true }
);

UserSchema.pre(&quot;save&quot;, async function () {
  // hash the password
  if (!this.isModified(&quot;password&quot;)) return;
  const salt = await bcrypt.genSalt(10);
  this.password = await bcrypt.hash(this.password, salt);
});
// Generate JWT
UserSchema.methods.createJWT = function () {
  return jwt.sign({ userId: this._id }, process.env.JWT_SECRET, {
    expiresIn: process.env.JWT_LIFETIME,
  });
};
// compare the entered password with the hashed password
UserSchema.methods.comparePassword = async function (candidatePassword) {
  const isMatch = await bcrypt.compare(candidatePassword, this.password);
  return isMatch;
};

export default mongoose.model(&quot;User&quot;, UserSchema);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;routes&lt;/h3&gt;
&lt;p&gt;I import the different routes into the server file to keep everythign clean. Here is the animesRoutes.js&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import express from &quot;express&quot;;
const router = express.Router();

import {
createAnime,
deleteAnime,
getAnimes,
} from &quot;../controllers/animesController.js&quot;;

// the apiLimiter middleware is used to limit the number of requests for registering and logging in
import rateLimiter from &quot;express-rate-limit&quot;;
const apiLimiter = rateLimiter({
windows: 15 * 60 * 1000, // 15 minutes
max: 500,
message: &quot;Too many requests from this IP, please try again after 15 minutes&quot;,
});

// the base URL
// app.use(&quot;/api/v1/animes&quot;, authenticateUser, animesRouter);

router.route(&quot;/&quot;).post(apiLimiter, createAnime).get(getAnimes);
// :id is a dynamic parameter
router.route(&quot;/:id&quot;).delete(deleteAnime);

export default router;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;utils&lt;/h3&gt;
&lt;p&gt;It contains the check permissions files which compare two user ids.&lt;/p&gt;
&lt;h3&gt;server.js&lt;/h3&gt;
&lt;p&gt;Relatively simple and clean setup. There are some protections in place.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;import express from &quot;express&quot;;
import dotenv from &quot;dotenv&quot;;
import &quot;express-async-errors&quot;;
import morgan from &quot;morgan&quot;;
import { dirname } from &quot;path&quot;;
import { fileURLToPath } from &quot;URL&quot;;
import path from &quot;path&quot;;

// protections
import helmet from &quot;helmet&quot;;
import xss from &quot;xss-clean&quot;;
import mongoSanitize from &quot;express-mongo-sanitize&quot;;

// db and authenticateUser
import connectDB from &quot;./db/connect.js&quot;;

// routers
import authRouter from &quot;./routes/authRoutes.js&quot;;
import animesRouter from &quot;./routes/animesRoutes.js&quot;;
import playlistsRouter from &quot;./routes/playlistsRoutes.js&quot;;

// middleware
import errorHandlerMiddleware from &quot;./middleware/error-handler.js&quot;;
import authenticateUser from &quot;./middleware/auth.js&quot;;

// Load environment variables from .env file
dotenv.config();

// start up the server
const app = express();

// get the app to use JSON as the default data format
app.use(express.json());

// protections
app.use(helmet.dnsPrefetchControl());
app.use(helmet.expectCt());
app.use(helmet.frameguard());
app.use(helmet.hidePoweredBy());
app.use(helmet.hsts());
app.use(helmet.ieNoOpen());
app.use(helmet.noSniff());
app.use(helmet.originAgentCluster());
app.use(helmet.permittedCrossDomainPolicies());
app.use(helmet.referrerPolicy());
app.use(helmet.xssFilter());

//sanitize input
app.use(XSS());
// prevents MongoDB operator injection from MongoDB queries
app.use(mongoSanitize());

// app level routes
app.use(&quot;/api/v1/auth&quot;, authRouter);
app.use(&quot;/api/v1/animes&quot;, authenticateUser, animesRouter);
app.use(&quot;/api/v1/playlists&quot;, authenticateUser, playlistsRouter);

// middleware
app.use(errorHandlerMiddleware);

if (process.env.NODE_ENV !== &quot;production&quot;) {
  app.use(morgan(&quot;dev&quot;));
}

// only when ready to deploy
const __dirname = dirname(fileURLToPath(import.meta.URL));
app.use(express.static(path.resolve(__dirname, &quot;./client/build&quot;)));

// only when ready to deploy
app.get(&quot;*&quot;, (req, res) =&gt; {
  res.sendFile(path.resolve(__dirname, &quot;./client/build&quot;, &quot;index.html&quot;));
});

// start the server

const port = process.env.PORT || 5000;

const start = async () =&gt; {
  try {
    await connectDB(process.env.MONGO_URL);
    app.listen(port, () =&gt; {
      console.log(`Server is listening on port ${port}...`);
    });
  } catch (error) {
    console.log(error);
  }
};

start();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Simplifying Your If Statements By Extracting Complex Conditions]]></title><description><![CDATA[Most of the time, we can make simple changes to increase the readability of our if statements For example: However, sometimes we can run…]]></description><link>https://zach-stone.netlify.app/simplifying_if_statements/</link><guid isPermaLink="false">https://zach-stone.netlify.app/simplifying_if_statements/</guid><pubDate>Mon, 04 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Most of the time, we can make simple changes to increase the readability of our if statements&lt;/h2&gt;
&lt;h3&gt;For example:&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;number &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; highestNumber&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;doSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// we can rewrite this as &lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;number &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; highestNumber&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;doSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;However, sometimes we can run into if statements that are a bit tough to read through:&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;type &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;admin&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;type &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;pastOrders&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;currentOrder&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;currentOrder&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;status&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;isPaid &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;currentOrder&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;orderTotal &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;isBigSpender &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; orderValue &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;  
      &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;USA&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Japan&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;location&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;doSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;img src=&quot;https://media.giphy.com/media/cFgb5p5e1My3K/giphy.gif&quot; width=&quot;100%&quot; style=&quot;width:100%&quot;&gt;
&lt;h2&gt;Let’s extract some of that logic out of of the if statement&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;HIGH_SPENDING_AREAS&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;USA&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Japan&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; isAdminOrManager &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;type &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;admin&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;type &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; hasPastOrder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;pastOrders&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; currentOrderIsValidAndPaid &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;currentOrder&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;status&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;isPaid &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; userIsFromHighSpendingArea &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;HIGH_SPENDING_AREAS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;location&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; isHighValueCustomer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;
  cartContext&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;cartId&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;currentOrder&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;checkout&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;orderTotal &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token operator&quot;&gt;?.&lt;/span&gt;isBigSpender &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; orderValue &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;userIsFromHighSpendingArea&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;isAdminOrManager &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;hasPastOrder &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; currentOrderIsValidAndPaid &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; isHighValueCustomer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;doSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Benefits of Extracting Complex Conditions&lt;/h2&gt;
&lt;h3&gt;1. Readability&lt;/h3&gt;
&lt;p&gt;Extracting complex conditions makes your code easier to read and understand.&lt;/p&gt;
&lt;h3&gt;2. Reusability&lt;/h3&gt;
&lt;p&gt;Once you’ve extracted complex conditions, you can reuse them in other parts of your codebase.&lt;/p&gt;
&lt;h3&gt;3. Testability&lt;/h3&gt;
&lt;p&gt;Extracted conditions can be independently tested, allowing you to validate their correctness in isolation.&lt;/p&gt;
&lt;h3&gt;4. Debugging&lt;/h3&gt;
&lt;p&gt;When debugging your code, having separate variables for extracted conditions allows you to inspect and monitor their values independently.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In the moment, it can be easy to just add another condition to an already long if statement in your codebase.&lt;/p&gt;
&lt;p&gt;For the sake of your future self and others, let’s try to make our code more readable..&lt;/p&gt;
&lt;p&gt;Did you find this blog post helpful?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why I Build Data Structures Outside Of Coding Problems]]></title><description><![CDATA[How comfortable are you with the data structures you use? My mentor, a professional C++ Engineer, always asks me to build data structures…]]></description><link>https://zach-stone.netlify.app/Walk Before You Run/</link><guid isPermaLink="false">https://zach-stone.netlify.app/Walk Before You Run/</guid><pubDate>Thu, 05 May 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;How comfortable are you with the data structures you use?&lt;/h2&gt;
&lt;p&gt;My mentor, a professional C++ Engineer, always asks me to build data structures repeatedly. Often back to back.&lt;/p&gt;
&lt;p&gt;While he could give me leet-code-style coding challenges, he thinks becoming extremely comfortable with data structures is more important in the early stages.&lt;/p&gt;
&lt;p&gt;I tend to agree. The more I build data structures, the more quickly I can solve problems with them.&lt;/p&gt;
&lt;h2&gt;Where to start&lt;/h2&gt;
&lt;p&gt;There are many great Youtube videos on data structures and several online courses.&lt;/p&gt;
&lt;p&gt;here are a few of my favorites&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=sVxBVvlnJsM&quot;&gt;DATA STRUCTURES you MUST know (as a Software Developer)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=8hly31xKli0&quot;&gt;Algorithms and Data Structures Tutorial - Full Course for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=1AJ4ldcH2t4&quot;&gt;Stacks &amp;#x26; Queues | Data Structures in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I also find typing “data structure you are learning” + “coding language” highly effective.&lt;/p&gt;
&lt;p&gt;Still not sure what to start with?&lt;/p&gt;
&lt;p&gt;Try completing my one week data structure challenge!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/zachinjapan/Data-Structures-1-Week-Challenge&quot;&gt;My Data Structures Challenge&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;What do you think?&lt;/h2&gt;
&lt;p&gt;Did you enjoy this post?&lt;/p&gt;
&lt;p&gt;Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How I Respond to Application Rejections]]></title><description><![CDATA[You got a reply!!!! But as you start reading more, something seems off. “We appreciate your application but have decided to go with another…]]></description><link>https://zach-stone.netlify.app/How I Respond to Application Rejections/</link><guid isPermaLink="false">https://zach-stone.netlify.app/How I Respond to Application Rejections/</guid><pubDate>Sat, 05 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;You got a reply!!!!&lt;/h2&gt;
&lt;p&gt;But as you start reading more, something seems off. “We appreciate your application but have decided to go with another candidate…&lt;/p&gt;
&lt;p&gt;Oh.&lt;/p&gt;
&lt;img src=&quot;https://media.giphy.com/media/T1WqKkLY753dZghbu6/giphy.gif&quot; width=&quot;70%&quot;&gt;
&lt;p&gt;You thought that was the one. Was all that work a waste?&lt;/p&gt;
&lt;h2&gt;There are two things you can do to turn the situation around.&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Think about the questions that tripped you up. Then, write them down and perfect the answer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Send a thank-you email.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;img src=&quot;https://media.giphy.com/media/ghuvaCOI6GOoTX0RmH/giphy.gif&quot; width=&quot;70%&quot;&gt;
&lt;h2&gt;A thank you email??! Yes.&lt;/h2&gt;
&lt;p&gt;While sending a thank-you email can feel backward, there might have been situations outside your control. For example, maybe an internal employee went for the same position.&lt;/p&gt;
&lt;h2&gt;Here is an idea of what to say&lt;/h2&gt;
&lt;p&gt;Dear (company and or hiring manager)&lt;/p&gt;
&lt;p&gt;I’m happy to hear you found the right candidate. Thank you for getting back to me and letting me know about the decision.&lt;/p&gt;
&lt;p&gt;I enjoyed learning about (company)&lt;/p&gt;
&lt;p&gt;I know that I am not in a position to ask for favors. Still, if you have a moment to spare, I would love any additional feedback about areas in my application that I could improve to increase my chances of becoming a (job title)&lt;/p&gt;
&lt;p&gt;Please do not feel obligated to answer this question, but if there was something you noticed, it would help me in my job search, and I would be so grateful.&lt;/p&gt;
&lt;p&gt;I hope everything works out with you and your new hire!&lt;/p&gt;
&lt;p&gt;Sincerely,
(your name)&lt;/p&gt;
&lt;h2&gt;A sense of respect and kindness can go a long way.&lt;/h2&gt;
&lt;p&gt;What do you think?&lt;/p&gt;
&lt;p&gt;Did you enjoy this post?&lt;/p&gt;
&lt;p&gt;Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Three Simple Tricks I Use To Make My Sites Load Faster]]></title><description><![CDATA[I love optimizing my page’s load time. Here are some tricks I use. 1. Compress Images I usually compress my images. Especially images that…]]></description><link>https://zach-stone.netlify.app/Three Simple Tricks I Use To Make My Sites Load Faster/</link><guid isPermaLink="false">https://zach-stone.netlify.app/Three Simple Tricks I Use To Make My Sites Load Faster/</guid><pubDate>Tue, 22 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I love optimizing my page’s load time.&lt;/p&gt;
&lt;img src=&quot;https://media.giphy.com/media/vLUhsxMfdVfS8/giphy.gif&quot; width=&quot;50%&quot;&gt;
&lt;p&gt;Here are some tricks I use.&lt;/p&gt;
&lt;h2&gt;1. Compress Images&lt;/h2&gt;
&lt;p&gt;I usually compress my images. Especially images that are used as thumbnails.&lt;/p&gt;
&lt;p&gt;I use &lt;a href=&quot;https://tinypng.com&quot;&gt;tinypng&lt;/a&gt;, but other websites exist.&lt;/p&gt;
&lt;p&gt;I have seen portfolio websites where the only reason it takes 5-10 seconds to load is that many high-quality images are used as thumbnails!!&lt;/p&gt;
&lt;p&gt;Not good.&lt;/p&gt;
&lt;h2&gt;2. Watch the Network Activity.&lt;/h2&gt;
&lt;p&gt;Recently I ran my portfolio website on Chrome, checking the network activity tab.&lt;/p&gt;
&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07mcrjowp0pxv436g6dm.png&quot; width=&quot;100%&quot; alt=&quot;404 missing image&quot;&gt;
&lt;p&gt;Uh oh!!! That 404 (bad request) is costing me 40ms on every load!&lt;/p&gt;
&lt;p&gt;I updated the image URL and saved 40ms!&lt;/p&gt;
&lt;img src=&quot;https://media.giphy.com/media/3oz8xBmTULwn1QSNgI/giphy.gif&quot; width=&quot;50%&quot;&gt;
&lt;h2&gt;3. Use Lazy Loading&lt;/h2&gt;
&lt;p&gt;My blog posts on my portfolio are displayed as gifs… gifs can be costly to load!&lt;/p&gt;
&lt;p&gt;Here is what the page loads like with the gifs rendered with your regular img tag&lt;/p&gt;
&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65utkl9qbia1cuj81hja.png&quot; width=&quot;100%&quot; alt=&quot;google chrome network tab&quot;&gt;
&lt;br/&gt;
&lt;p&gt;The load time is&lt;/p&gt;
&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s85lzk3ct2vk84szudnc.png&quot; width=&quot;50%&quot; alt=&quot;google chrome network tab&quot;&gt;
&lt;p&gt;Those gifs are blocking the site’s initial load. All of that for images that the user will not see until much farther down the page.&lt;/p&gt;
&lt;p&gt;Let’s add lazy loading.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;// react component
 &amp;lt;CardMedia
 ... some react stuff ...
 loading=&quot;lazy&quot;
 /&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Watch as the images load once the user reaches them.&lt;/p&gt;
&lt;img src=&quot;https://media.giphy.com/media/I69J6ecR0a2g8tzCe3/giphy.gif&quot; width=&quot;100%&quot;&gt;
&lt;h2&gt;But what about the load time?&lt;/h2&gt;
&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qo678y05pi4tvjg39ut2.png&quot; width=&quot;100%&quot; alt=&quot;google chrome network tab&quot;&gt;
&lt;h2&gt;The result is&lt;/h2&gt;
&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9zf1fiixq2bnf31le01.png&quot; width=&quot;50%&quot; alt=&quot;google chrome network tab&quot;&gt;
&lt;img src=&quot;https://media.giphy.com/media/F0XPSvNDyGpos/giphy.gif&quot; width=&quot;50%&quot;&gt;
&lt;h2&gt;What do you think?&lt;/h2&gt;
&lt;p&gt;Did you enjoy this post?&lt;/p&gt;
&lt;p&gt;Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using Recursion to Insert Values Into a Sorted Binary Tree]]></title><description><![CDATA[I have been playing around with sorted binary trees recently. In computer science, a binary search tree (BST), also called an ordered or…]]></description><link>https://zach-stone.netlify.app/Using Recursion to Insert Values Into a Sorted Binary Tree/</link><guid isPermaLink="false">https://zach-stone.netlify.app/Using Recursion to Insert Values Into a Sorted Binary Tree/</guid><pubDate>Mon, 14 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;I have been playing around with sorted binary trees recently.&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted binary tree data structure whose internal nodes each store a key greater than all the keys in the node’s left subtree and less than those in its right subtree. The time complexity of operations on the binary search tree is directly proportional to the height of the tree.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;img src=&quot;https://media.giphy.com/media/qcy6cSzrtP7ybXvZvn/giphy.gif&quot; width=&quot;100%&quot;&gt;
&lt;h2&gt;My favorite part about binary trees is using recursion to travel down the nodes.&lt;/h2&gt;
&lt;p&gt;I do two things for the insert() method of my tree.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;I check if the tree is empty. If so, I add the node.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I create a recursive function to travel down the tree and eventually add the new node if it hits the end of the branch (no more nodes)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Let’s get cracking!&lt;/h2&gt;
&lt;h2&gt;First part = check if the list is empty and if it is add a new node as the root and return&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;// node class for reference
class Node {
  constructor(value){
    this.value = value;
    this.left = null;
    this.right = null
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;    let newNode = new Node(value);
    // if empty
    if (this.count === 0) {
      this.root = newNode;
      this.count++;
      return;
    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Still with me?&lt;/h2&gt;
&lt;p&gt;Cool! so here’s the fun part&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;  this.count++;
    //recursive call
    const searchTree = node =&gt; {
      // less than
      if (value &amp;lt; node.value) {
        if (!node.left) {
          node.left = newNode;
        } else {
          searchTree(node.left)
        }
      greater than
      } else if (value &gt; node.value) {
        if (!node.right) {
          node.right = newNode;
        } else {
          searchTree(node.right);
        }
      }
    }
    //start of recursive call
    searchTree(this.root)

  }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Let’s&lt;/p&gt;
&lt;img src=&quot;https://media.giphy.com/media/Qvps3j9alpsQSARLJk/giphy.gif&quot;&gt;
&lt;p&gt;We have the following tree.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;

            31
        30
    20      29
10
    5
        4

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;We want to add 27&lt;/h2&gt;
&lt;p&gt;1st. we check if it is empty (it’s not)
2nd we start the recursive call with the root (10)&lt;/p&gt;
&lt;h2&gt;first call&lt;/h2&gt;
&lt;p&gt;if (27 &amp;#x3C; 10) …false!&lt;/p&gt;
&lt;p&gt;goes to else if (27 &gt; 10) …true!&lt;/p&gt;
&lt;h2&gt;inside of else if&lt;/h2&gt;
&lt;p&gt;if (!10.right) false!!!
else {calls the recursive function but with 20}&lt;/p&gt;
&lt;h2&gt;this continues till it hits 29, at which&lt;/h2&gt;
&lt;p&gt;if (27 &amp;#x3C; 29) …true!
if (!node.left)…TRUE!!!!!
ok! we’re done!&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;node.left = newNode;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;img src=&quot;https://media.giphy.com/media/229OX0vSVNys10AZnS/giphy.gif&quot; width=&quot;100%&quot;&gt;
&lt;h2&gt;What do you think?&lt;/h2&gt;
&lt;p&gt;Did you enjoy this post?&lt;/p&gt;
&lt;p&gt;Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[count++ != ++count]]></title><description><![CDATA[What is the result of this code? …it’s… Let’s learn about post-increment and pre-increment The pre-increment and pre-decrement operators…]]></description><link>https://zach-stone.netlify.app/count++ != ++count/</link><guid isPermaLink="false">https://zach-stone.netlify.app/count++ != ++count/</guid><pubDate>Sat, 05 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;img src=&quot;https://media.giphy.com/media/3o6nV5TdYIA48G7VYI/giphy.gif&quot; width=&quot;100%&quot; style=&quot;width:100%&quot;&gt;
&lt;h2&gt;What is the result of this code?&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let count = 0;
console.log(count++)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;…it’s…&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;
0

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;img src=&quot;https://media.giphy.com/media/3o72F8t9TDi2xVnxOE/giphy.gif&quot; width=&quot;100%&quot; style=&quot;width:100%&quot;&gt;
&lt;h2&gt;Let’s learn about post-increment and pre-increment&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The pre-increment and pre-decrement operators increment (or decrement) their operand by 1, and the value of the expression is the resulting incremented (or decremented) value.
The post-increment and post-decrement operators increase (or decrease) the value of their operand by 1, but the value of the expression is the operand’s value before the increment (or decrement) operation. - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let’s look at what’s going on “under the hood”.&lt;/p&gt;
&lt;p&gt;Here is a representation using a JavaScript class object.&lt;/p&gt;
&lt;p&gt;postAdd = {count++}
preAdd = {++count}&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;class Counter {
  constructor (){
    this.count = 0
  }
  postAdd(){
    let oldCount = this.count;
    this.count+=1;
    return oldCount
  }
  preAdd(){
    this.count += 1;
    return this.count
  }
}

let count = new Counter();

console.log(count.postAdd()) // 0

console.log(count.preAdd()) // 2 (the first console.log still increments!!!)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;In my own words&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;{variable}++ can be used when you don’t reference the increased variable in that function call, and ++{variable} is valid when you need to reference the incremented variable immediately. -Zach Stone&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Technically, pre increment is also faster since it is not creating a new variable each time.&lt;/p&gt;
&lt;h2&gt;How do you decide whether to use pre or post-increment?&lt;/h2&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[this.concept = important]]></title><description><![CDATA[What is ‘this’? A property of an execution context (global, function, or eval) that, in non–strict mode, is always a reference to an object…]]></description><link>https://zach-stone.netlify.app/This.Concept = important/</link><guid isPermaLink="false">https://zach-stone.netlify.app/This.Concept = important/</guid><pubDate>Tue, 18 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;What is ‘this’?&lt;/h2&gt;
&lt;img src=&quot;https://media.giphy.com/media/26FLgGTPUDH6UGAbm/giphy.gif&quot; width=&quot;100%&quot; style=&quot;width:100%&quot;&gt;
&lt;blockquote&gt;
&lt;p&gt;A property of an execution context (global, function, or eval) that, in non–strict mode, is always a reference to an object and in strict mode can be any value. (MDN)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Let’s look at some analogies&lt;/h2&gt;
&lt;p&gt;jacket.this = you&lt;/p&gt;
&lt;p&gt;jacket button.this = jacket&lt;/p&gt;
&lt;p&gt;the plastic part of the button.this = jacket button&lt;/p&gt;
&lt;p&gt;Make sense?&lt;/p&gt;
&lt;h2&gt;What is ‘this’ in your browser? Let’s see!&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;console.log(this)
[Log] Window {listeners: Object, initPagination: function, timeAgo: function, sendFetch: function, setCurrentUserToNavBar: function, …}…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It’s the window!&lt;/p&gt;
&lt;h2&gt;How do we use ‘this’?&lt;/h2&gt;
&lt;p&gt;There are many uses for ‘this.’ I also am aware that there are specific considerations when using ‘this’ in functions depending on whether they are arrow functions or “use strict” is on.&lt;/p&gt;
&lt;p&gt;Let’s talk about the most common use case I am aware of.&lt;/p&gt;
&lt;h2&gt;‘this’ in Classes&lt;/h2&gt;
&lt;p&gt;A JavaScript class is an object factory. The constructor is the part that makes the object.&lt;/p&gt;
&lt;p&gt;Let’s make two person objects using the Person class and assign them a name using ‘this.’&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;class Person {
  constructor(name) {
    this.name = name;
  }

    sayHi() {
        return (`Hi, I&apos;m ${this.name}`);
        }
}

const Person1 = new Person (&quot;Bob&quot;);
const Person2 = new Person (&quot;Jill&quot;);

console.log(Person1.name);
// Bob
console.log(Person2.name);
// Jill
console.log(Person1.sayHi());
// Hi, I&apos;m Bob
console.log(Person2.sayHi());
// Hi, I&apos;m Jill&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;img src=&quot;https://media.giphy.com/media/Rl9Yqavfj2Ula/giphy.gif&quot; width=&quot;100%&quot; style=&quot;width:100%&quot;&gt;
&lt;p&gt;I hope that helped you understand what ‘this’ is.&lt;/p&gt;
&lt;p&gt;My favorite use of ‘this’ is in linked lists… but that is a topic for a different blog post!&lt;/p&gt;
&lt;p&gt;Here are some resources to learn more about ‘this.’&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=gvicrj31JOM&quot;&gt;JavaScript this Keyword&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=YOlr79NaAtQ&quot;&gt;What is THIS in JavaScript? in 100 seconds&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Did you enjoy this article? Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using &lt;a href=&quot;https://zstone.dev&quot;&gt;my website&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[An Introduction to Recursion]]></title><description><![CDATA[On my journey to becoming a web developer in Japan, I have found two concepts difficult to understand. The first, is higher order functions…]]></description><link>https://zach-stone.netlify.app/recursion/</link><guid isPermaLink="false">https://zach-stone.netlify.app/recursion/</guid><pubDate>Sat, 01 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;On my journey to becoming a web developer in Japan, I have found two concepts difficult to understand. The first, is &lt;a href=&quot;https://dev.to/zachinjapan/higher-order-functions-4h7e&quot;&gt;higher order functions&lt;/a&gt;. The second is recursion.&lt;/p&gt;
&lt;h2&gt;What is recursion?&lt;/h2&gt;
&lt;br&gt;
&lt;img width=&quot;100%&quot; style=&quot;width:100%&quot; src=&quot;https://media.giphy.com/media/xThuWu82QD3pj4wvEQ/giphy.gif&quot;&gt;
&lt;blockquote&gt;
&lt;p&gt;Recursion (adjective: recursive) occurs when a thing is defined in terms of itself or of its type… a function being defined is applied within its own definition. While this apparently defines an infinite number of instances (function values), it is often done in such a way that no infinite loop or infinite chain of references can occur. - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Now, in layman’s terms&lt;/h2&gt;
&lt;br&gt;
&lt;blockquote&gt;
&lt;p&gt;Recursion is when the function uses itself in a loop until some test, defined within itself, is met. - Zach Stone&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Let’s look at an example.&lt;/h2&gt;
&lt;br&gt;
&lt;p&gt;Define a function that takes an input number. The program console logs the number and every subsequent number reducing by one each time. It does this until it reaches 0. When the function reaches 0, it should console log “I’m finished.”&lt;/p&gt;
&lt;h2&gt;without recursion (iteratively)&lt;/h2&gt;
&lt;br&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;const countDown = (num) =&gt; {
  for (let x = num; x &gt;= 0; x--) {
    if (x === 0) {
      console.log(&quot;I&apos;m finished&quot;);
    } else {
      console.log(x);
    }
  }
};

countDown(20); // 20 , 19, 18, 17, 16, 15 ,14 ,13 ,12 ,11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, &quot;I&apos;m finished&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;with recursion (recursively)&lt;/h2&gt;
&lt;br&gt;
&lt;p&gt;The key is thinking about the &lt;strong&gt;base case&lt;/strong&gt;. That’s the test to see if we can end the loop.&lt;/p&gt;
&lt;p&gt;The base case in this situation is&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;if (x === 0)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So we need to rewrite the function.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;
const countDown = (num) =&gt; {
  if (num === 0) {
    console.log(&quot;I&apos;m finished&quot;);
  } else {
    console.log(num);
    return countDown(num - 1);
  }
};

countDown(20); // 20 , 19, 18, 17, 16, 15 ,14 ,13 ,12 ,11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, &quot;I&apos;m finished&quot;



&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;We did it!!!!&lt;/h2&gt;
&lt;br&gt;
&lt;img width=&quot;100%&quot; style=&quot;width:100%&quot; src=&quot;https://media.giphy.com/media/3oz8xynJ88hmIdCCOI/giphy.gif&quot;&gt;
&lt;p&gt;The function calls itself over and over, reducing by 1 each time. Finally, when the base case is met, it console logs “I’m finished” and ends.&lt;/p&gt;
&lt;h2&gt;Here are some resources to learn more&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rf60MejMz3E&quot;&gt;Recursion in 100 Seconds &amp;#x3C;3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=lMBVwYrmFZQ&quot;&gt;A great intro to recursion by Colte Steele&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.codewars.com/collections/recursion-1&quot;&gt;Codewars playlist of recursion problems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.freecodecamp.org/news/understanding-recursion-in-programming/&quot;&gt;freeCodeCamp article&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=IJDJ0kBx2LM&quot;&gt;freeCodeCamp YouTube vid&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Did you enjoy this article? Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How I Studied For The Coding Bootcamp Technical Interview]]></title><description><![CDATA[This was me Maybe you’re in a similar situation…Maybe not. Either way, I hope you enjoy reading about my study process using free resources…]]></description><link>https://zach-stone.netlify.app/bootcamp_coding_interview/</link><guid isPermaLink="false">https://zach-stone.netlify.app/bootcamp_coding_interview/</guid><pubDate>Mon, 20 Dec 2021 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;This was me&lt;/h2&gt;
&lt;div class=&quot;gatsby-resp-iframe-wrapper&quot; style=&quot;padding-bottom: 55.41666666666667%; position: relative; height: 0; overflow: hidden; margin-bottom: 1.0725rem&quot; &gt; &lt;iframe src=&quot;https://giphy.com/embed/IPbS5R4fSUl5S&quot; frameborder=&quot;0&quot; class=&quot;giphy-embed&quot; allowfullscreen=&quot;&quot; style=&quot; position: absolute; top: 0; left: 0; width: 100%; height: 100%; &quot;&gt;&lt;/iframe&gt;&lt;p&gt;&lt;a href=&quot;https://giphy.com/gifs/IPbS5R4fSUl5S&quot;&gt;via GIPHY&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;
&lt;/br&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; zach &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;lotsOfTime&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;haveExtraMoney&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;studyingToGetIntoACodingBootcamp&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Maybe you’re in a similar situation…Maybe not.&lt;/p&gt;
&lt;p&gt;Either way, I hope you enjoy reading about my study process using free resources.&lt;/p&gt;
&lt;h3&gt;The Free Resources I Used to Review Javascript&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;left&quot;&gt;Name&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Notes&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;a href=&quot;https://eloquentjavascript.net&quot;&gt;Eloquent Javascript &lt;/a&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;chapters 1-6 especially&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Book (free online)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;a href=&quot;https://www.codecademy.com/learn&quot;&gt;Codecademy &lt;/a&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Intro to JS Course&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;interactive(text)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;a href=&quot;https://www.fullstackacademy.com/bootcamp-prep&quot;&gt;Fullstack Acadamy&lt;/a&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;The bootcamp prep has a free option&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;interactive(video)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;a href=&quot;https://www.codewars.com/dashboard&quot;&gt;Codewars &lt;/a&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;focus on level 7/8&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;gamified algorithm exercises&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;&lt;a href=&quot;https://youtube.com&quot;&gt;Youtube &lt;/a&gt;&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;the most dangerous of all resources&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;passive (video)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;What I did&lt;/h3&gt;
&lt;p&gt;I read Eloquent Javascript in the morning with my coffee, highlighting and working through the exercises up to chapter 6.&lt;/p&gt;
&lt;p&gt;I completed the entire intro to JS course about one unit per day (pro is free for 7 days if you want to do the quizes/‘projects’)&lt;/p&gt;
&lt;p&gt;I completed the entire Full-stack free boot camp prep course. I found the videos excellent and completed &lt;del&gt;all&lt;/del&gt; … &lt;del&gt;most&lt;/del&gt; … some of the example problems.&lt;/p&gt;
&lt;p&gt;I did 1-3 code wars problems everyday at level 7/8&lt;/p&gt;
&lt;p&gt;and…&lt;/p&gt;
&lt;h2&gt;I got in&lt;/h2&gt;
&lt;div style=&quot;width:100%;height:0;padding-bottom:100%;position:relative;&quot;&gt;&lt;iframe src=&quot;https://giphy.com/embed/PQ0VI3S5vqL5pwQQJX&quot; width=&quot;100%&quot; height=&quot;100%&quot; style=&quot;position:absolute&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://giphy.com/gifs/TheSwoon-PQ0VI3S5vqL5pwQQJX&quot;&gt;via GIPHY&lt;/a&gt;&lt;/p&gt;
&lt;/br&gt;
&lt;p&gt;At the end of the day, there are many other great resources like &lt;a href=&quot;https://www.freecodecamp.org&quot;&gt;freeCodeCamp &lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But try not to get lost in finding the perfect resource.&lt;/p&gt;
&lt;p&gt;just focus on&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;one line at a time.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You got this…👍&lt;/p&gt;
&lt;h3&gt;NOW CLOSE THIS TAB AND GO STUDY!&lt;/h3&gt;
&lt;/br&gt;</content:encoded></item><item><title><![CDATA[Higher Order Functions]]></title><description><![CDATA[I was recently confused by this simple question. Did you try to solve it? Here is one possible answer That, my friend, is a higher-order…]]></description><link>https://zach-stone.netlify.app/Higher Order Functions/</link><guid isPermaLink="false">https://zach-stone.netlify.app/Higher Order Functions/</guid><pubDate>Tue, 07 Dec 2021 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;I was recently confused by this simple question.&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
Declare a function &apos;add&apos;.

&apos;add&apos; takes one number input: &apos;x&apos;.

&apos;add&apos; returns a function that takes one number input &apos;y&apos;.

This returned function returns the sum of &apos;x&apos; and &apos;y&apos; when run.
*/&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div style=&quot;width:100%;height:0;padding-bottom:100%;position:relative;&quot;&gt;&lt;iframe src=&quot;https://giphy.com/embed/FcuiZUneg1YRAu1lH2&quot; width=&quot;100%&quot; height=&quot;100%&quot; style=&quot;position:absolute&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://giphy.com/gifs/sunnyfxx-always-sunny-iasip-its-FcuiZUneg1YRAu1lH2&quot;&gt;via GIPHY&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Did you try to solve it? Here is one possible answer&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;innerFunction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; y
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;//example&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; addTwo &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;//stores the inner function with x inherited&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sum &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addTwo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// inputs y as 3&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;//sum = 5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;That, my friend, is a higher-order function.&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://eloquentjavascript.net/05_higher_order.html&quot; title=&quot;EJS&quot;&gt;Elqouent Javascript Chapter 5&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Functions that operate on other functions,
either by taking them as arguments or
by returning them, are called higher-order functions.&lt;/p&gt;
&lt;p&gt;The code above is an example of returning a function that inherits the outer scope’s function variable&lt;/p&gt;
&lt;p&gt;Here is an example of using a function as an input&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;greetPerson&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; greetingBuilder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;greetingBuilder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;howsItGoing&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;! How&apos;s it going?&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;hello&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;Hello &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;greetPerson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Jon&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; howsItGoing&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Jon! Hows&apos;it going?&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;greetPerson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Fred&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; hello&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Hello Fred&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Not too scary, after all.&lt;/p&gt;
&lt;p&gt;You might have noticed that there are a few Array Methods that take functions as inputs… well…
that…
makes them HIGHER ORDER FUNCTIONS!!&lt;/p&gt;
&lt;br/&gt;
&lt;div style=&quot;width:100%;height:0;padding-bottom:60%;position:relative;&quot;&gt;&lt;iframe src=&quot;https://giphy.com/embed/XR9Dp54ZC4dji&quot; width=&quot;100%&quot; height=&quot;100%&quot; style=&quot;position:absolute&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://giphy.com/gifs/mrw-thanks-server-XR9Dp54ZC4dji&quot;&gt;via GIPHY&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;My favorite array method&lt;/h3&gt;
&lt;h5&gt;Array.prototype.map()&lt;/h5&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map&quot; title=&quot;MDN&quot;&gt;MDN article on .map&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; array1 &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// pass a function to map&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; map1 &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; array1&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;map1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// expected output: Array [2, 8, 18, 32]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Cool right?&lt;/p&gt;
&lt;h1&gt;Here are some free resources&lt;/h1&gt;
&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://eloquentjavascript.net/05_higher_order.html&quot; title=&quot;EJS&quot;&gt;Elqouent Javascript Chapter 5&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.codewars.com/collections/higher-order-functions&quot; title=&quot;code wars&quot;&gt;Code Wars Higher Order Function Questions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.freecodecamp.org/news/a-quick-intro-to-higher-order-functions-in-javascript-1a014f89c6b/&quot; title=&quot;freeCodeCamp&quot;&gt;FreeCodeCamp Article&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=BMUiFMZr7vk&quot; title=&quot;youtube&quot;&gt;Great youtube vid&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p&gt;Did you enjoy this article? Or did I get something wrong?&lt;/p&gt;
&lt;p&gt;Feel free to contact me using my &lt;a href=&quot;https://zstone.dev&quot; title=&quot;Zach&amp;#x27;s website&quot;&gt;website&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a fantastic day!&lt;/p&gt;</content:encoded></item></channel></rss>