<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Realised-Prophets</title>
    <description>The latest articles on DEV Community by Realised-Prophets (@realisedprophets).</description>
    <link>https://dev.to/realisedprophets</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F907604%2Ff7b04b08-4ca1-403d-9591-fa21d9c88362.jpeg</url>
      <title>DEV Community: Realised-Prophets</title>
      <link>https://dev.to/realisedprophets</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/realisedprophets"/>
    <language>en</language>
    <item>
      <title>Great tutorial by @nsebhastian on .map()</title>
      <dc:creator>Realised-Prophets</dc:creator>
      <pubDate>Fri, 30 Dec 2022 17:49:52 +0000</pubDate>
      <link>https://dev.to/realisedprophets/great-tutorial-by-nsebhastian-on-map-39ia</link>
      <guid>https://dev.to/realisedprophets/great-tutorial-by-nsebhastian-on-map-39ia</guid>
      <description>&lt;p&gt;I really enjoyed this tutorial:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/javascript-map-how-to-use-the-js-map-function-array-method/" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/javascript-map-how-to-use-the-js-map-function-array-method/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I especially appreciate the final video which goes into detail about the syntax and different arguments you can give the .map() method. &lt;/p&gt;

&lt;p&gt;Spoiler! Here's my solution to the final challenge in the third video.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let bio = completeUserData.map(function(element, index, array) {
    return `"${index + 1}. ${element.firstName} is from ${element.additionalInfo.hometown}. 
    ${element.pronouns.main.capitalized} has a ${element.additionalInfo.pet.species} named 
    ${element.additionalInfo.pet.name}. ${element.pronouns.possessive.capitalized} favorite color is 
    ${element.additionalInfo.favoriteColor} and ${element.pronouns.possessive.lowerCase} favorite food is 
    ${element.additionalInfo.favoriteFood}. ${element.pronouns.possessive.capitalized} siblings are 
    ${element.additionalInfo.siblings.slice(0, -1).join(', ')} and ${element.additionalInfo.siblings.slice(-1)}.`
});

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

&lt;/div&gt;



</description>
      <category>mentalhealth</category>
      <category>career</category>
    </item>
    <item>
      <title>How to Factorialise a Number (and not end up in a spiralling void of zeros)</title>
      <dc:creator>Realised-Prophets</dc:creator>
      <pubDate>Sat, 19 Nov 2022 12:52:13 +0000</pubDate>
      <link>https://dev.to/realisedprophets/how-to-factorialise-a-number-and-not-end-up-in-spiralling-void-of-zeros-4cf7</link>
      <guid>https://dev.to/realisedprophets/how-to-factorialise-a-number-and-not-end-up-in-spiralling-void-of-zeros-4cf7</guid>
      <description>&lt;p&gt;Hey! So we want our code to do this: &lt;code&gt;5! = 1 * 2 * 3 * 4 * 5 = 120&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This is how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function factorialise(num) {
  let result = 1; 
  for (let i = num; i &amp;gt; 0; i--) {
    result *= i;
  }
  return result;
}
factorialise(5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how (I think) it works: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We start with a function that takes the number we want to factorialise as its argument.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, we need somewhere to store our result so we create a &lt;code&gt;result&lt;/code&gt; variable and initialise it to 1. It's 1 because we want to start all factorialising from there, if it were 0 we would end up in a spiralling void of nothingness because we'd be multiplying our values by 0 :(  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next we make a for loop. 1) set &lt;code&gt;i&lt;/code&gt; as &lt;code&gt;num&lt;/code&gt;. 2) the condition is that if &lt;code&gt;i&lt;/code&gt; is greater than &lt;code&gt;0&lt;/code&gt; then we will 3) decrease the value of &lt;code&gt;i&lt;/code&gt; (which has the same value as num in the first iteration) by 1 so that we can cycle through all the numbers until (but not including) 0. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now if we console.log we get this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
4
3
2
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great. So our loop is working. First it passes in the the original input number, then it decreases until 1. Now we need to find a way to multiply each value passed in. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;So we do this: &lt;code&gt;result *= i;&lt;/code&gt;. Remember that result is initialised to 1 so in the first iteration it's doing &lt;code&gt;1 * 5 = 5&lt;/code&gt;. In the next iteration our &lt;code&gt;result&lt;/code&gt; variable is now &lt;code&gt;5&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; has undergone one negative iteration resulting in its value now being &lt;code&gt;4&lt;/code&gt;. So it's doing &lt;code&gt;5 * 4 = 20&lt;/code&gt; (new result * corresponding decreased interation of &lt;code&gt;i&lt;/code&gt;). If we &lt;code&gt;console.log()&lt;/code&gt; here we can see how it works its way through.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
20
60
120
120
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how the total is repeated twice. I think this is because the last iteration is 1, so it's essentially doing &lt;code&gt;120 * 1 = 120&lt;/code&gt;. This does't really matter or affect the result, but it's still an unnecessary iteration. If we wanted to get rid of it we could go back to the for loop and change the condition to &lt;code&gt;i &amp;gt; 1&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ok, so now we have our result stored in our er.. &lt;code&gt;result&lt;/code&gt; variable. Next we just need to return our result. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is an explanation for myself really, but if you found it useful then all the better. If you see a mistake somewhere be sure to let me know, I'd appreciate that very much!&lt;/p&gt;

&lt;p&gt;Love, &lt;/p&gt;

</description>
      <category>nim</category>
    </item>
    <item>
      <title>Reversing a string</title>
      <dc:creator>Realised-Prophets</dc:creator>
      <pubDate>Thu, 17 Nov 2022 11:27:39 +0000</pubDate>
      <link>https://dev.to/realisedprophets/reversing-a-string-1ijj</link>
      <guid>https://dev.to/realisedprophets/reversing-a-string-1ijj</guid>
      <description>&lt;p&gt;I'm currently working through freeCodeCamp's 300h javascript course. One of the algorithm challenges is to reverse a string. I solved this with a &lt;code&gt;for&lt;/code&gt; loop, &lt;code&gt;unshift()&lt;/code&gt; and &lt;code&gt;join()&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function reverseString(str) {
  let arr = [];
  for (let i = 0; i &amp;lt; str.length; i++) {
    arr.unshift(str[i]);
  }
  return arr.join(""); 
}

reverseString("Hello")

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I declared an empty array to store the separate characters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I wrote your usual FOR loop to iterate through the input string characters. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I used the unshift method because this pushes each new letter to the front, starting with H into my empty &lt;code&gt;arr&lt;/code&gt; variable. It iterates though it like this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'H' ]
[ 'e', 'H' ]
[ 'l', 'e', 'H' ]
[ 'l', 'l', 'e', 'H' ]
[ 'o', 'l', 'l', 'e', 'H' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so by the end of the loop you end up with this array of letters which are in the reverse order.&lt;/p&gt;

&lt;p&gt;4 . Now I have an array with the desired order, however, the challenge wants a single string. A quick google search provided me with the &lt;code&gt;.join()&lt;/code&gt; method, which I then use on my &lt;code&gt;arr&lt;/code&gt; variable. The result is &lt;code&gt;olleH&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When I finished I looked up a few other ways of doing this. I'll post them another day!&lt;/p&gt;

&lt;p&gt;Love, RP&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>freecodecamp</category>
      <category>newbie</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
