<?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: Roldán Francisco</title>
    <description>The latest articles on DEV Community by Roldán Francisco (@roldn).</description>
    <link>https://dev.to/roldn</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%2F804965%2F5aa2d193-9e1a-491c-b184-a418172bcf90.jpg</url>
      <title>DEV Community: Roldán Francisco</title>
      <link>https://dev.to/roldn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/roldn"/>
    <language>en</language>
    <item>
      <title>Another wall climbed</title>
      <dc:creator>Roldán Francisco</dc:creator>
      <pubDate>Sun, 30 Jan 2022 19:23:41 +0000</pubDate>
      <link>https://dev.to/roldn/another-wall-climbed-man</link>
      <guid>https://dev.to/roldn/another-wall-climbed-man</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Problem: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Complete the code for the &lt;code&gt;squareList&lt;/code&gt; function using any combination of &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;. The function should return a new array containing the &lt;strong&gt;squares of only the positive integers&lt;/strong&gt; (decimal numbers are not integers) when an array of real numbers is passed to it. An example of an array of real numbers is [-3, 4.8, 5, 3, -3.2].&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note: Your function &lt;strong&gt;should not use&lt;/strong&gt; any kind of &lt;code&gt;for&lt;/code&gt; or &lt;code&gt;while&lt;/code&gt; loops or the &lt;code&gt;forEach()&lt;/code&gt; function.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CODE:&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const squareList = arr =&amp;gt; {

  // Only change code below this line

  return [...arr].filter(x =&amp;gt; Number.isInteger(x) &amp;amp;&amp;amp; x &amp;gt; 0).map(x =&amp;gt; x**2);

  // Only change code above this line
};

const squaredIntegers = squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]);
console.log(squaredIntegers);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Personal Note:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It took me like 5 hours complete this exercise.&lt;br&gt;
This are the &lt;strong&gt;3 most important lessons&lt;/strong&gt; for me &lt;strong&gt;so far&lt;/strong&gt;:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Try to not get distracted so easley&lt;/li&gt;
&lt;li&gt;White noise better than trapp for coding &lt;/li&gt;
&lt;li&gt;Enjoy the process of strugling with the first steps &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>I did it. *sobbing*.</title>
      <dc:creator>Roldán Francisco</dc:creator>
      <pubDate>Sun, 30 Jan 2022 04:13:01 +0000</pubDate>
      <link>https://dev.to/roldn/i-did-it-sobbing-1cg9</link>
      <guid>https://dev.to/roldn/i-did-it-sobbing-1cg9</guid>
      <description>&lt;p&gt;Just bearly now. After HOURS of reading and going back an foward through different YT videos can i sort of understand the usage of map, filter, &amp;amp; reduce. (JS methods).&lt;/p&gt;

&lt;p&gt;I'll let the exercise below:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The variable &lt;code&gt;watchList&lt;/code&gt; holds an array of objects with information on several movies. Use reduce to find the average IMDB rating of the movies directed by &lt;code&gt;"Christopher Nolan"&lt;/code&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// The global variable

 const watchList = [
   {
     "Title": "Inception",
     "Year": "2010",
     "Rated": "PG-13",
     "Released": "16 Jul 2010",
     "Runtime": "148 min",
     "Genre": "Action, Adventure, Crime",
     "Director": "Christopher Nolan",
     "Writer": "Christopher Nolan",
     "Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
     "Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
     "Language": "English, Japanese, French",
     "Country": "USA, UK",
     "Awards": "Won 4 Oscars. Another 143 wins &amp;amp; 198 nominations.",
     "Poster": "http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
     "Metascore": "74",
     "imdbRating": "8.8",
     "imdbVotes": "1,446,708",
     "imdbID": "tt1375666",
     "Type": "movie",
     "Response": "True"
   },
   {
     "Title": "Interstellar",
     "Year": "2014",
     "Rated": "PG-13",
     "Released": "07 Nov 2014",
     "Runtime": "169 min",
     "Genre": "Adventure, Drama, Sci-Fi",
     "Director": "Christopher Nolan",
     "Writer": "Jonathan Nolan, Christopher Nolan",
     "Actors": "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow",
     "Plot": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
     "Language": "English",
     "Country": "USA, UK",
     "Awards": "Won 1 Oscar. Another 39 wins &amp;amp; 132 nominations.",
     "Poster": "http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg",
     "Metascore": "74",
     "imdbRating": "8.6",
     "imdbVotes": "910,366",
     "imdbID": "tt0816692",
     "Type": "movie",
     "Response": "True"
   },
   {
     "Title": "The Dark Knight",
     "Year": "2008",
     "Rated": "PG-13",
     "Released": "18 Jul 2008",
     "Runtime": "152 min",
     "Genre": "Action, Adventure, Crime",
     "Director": "Christopher Nolan",
     "Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
     "Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
     "Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
     "Language": "English, Mandarin",
     "Country": "USA, UK",
     "Awards": "Won 2 Oscars. Another 146 wins &amp;amp; 142 nominations.",
     "Poster": "http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg",
     "Metascore": "82",
     "imdbRating": "9.0",
     "imdbVotes": "1,652,832",
     "imdbID": "tt0468569",
     "Type": "movie",
     "Response": "True"
   },
   {
     "Title": "Batman Begins",
     "Year": "2005",
     "Rated": "PG-13",
     "Released": "15 Jun 2005",
     "Runtime": "140 min",
     "Genre": "Action, Adventure",
     "Director": "Christopher Nolan",
     "Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
     "Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
     "Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
     "Language": "English, Urdu, Mandarin",
     "Country": "USA, UK",
     "Awards": "Nominated for 1 Oscar. Another 15 wins &amp;amp; 66 nominations.",
     "Poster": "http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg",
     "Metascore": "70",
     "imdbRating": "8.3",
     "imdbVotes": "972,584",
     "imdbID": "tt0372784",
     "Type": "movie",
     "Response": "True"
   },
   {
     "Title": "Avatar",
     "Year": "2009",
    "Rated": "PG-13",
     "Released": "18 Dec 2009",
     "Runtime": "162 min",
     "Genre": "Action, Adventure, Fantasy",
     "Director": "James Cameron",
     "Writer": "James Cameron",
     "Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
     "Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
     "Language": "English, Spanish",
     "Country": "USA, UK",
     "Awards": "Won 3 Oscars. Another 80 wins &amp;amp; 121 nominations.",
     "Poster": "http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg",
     "Metascore": "83",
     "imdbRating": "7.9",
     "imdbVotes": "876,575",
     "imdbID": "tt0499549",
     "Type": "movie",
     "Response": "True"
   }
 ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Answer:
&lt;/h2&gt;



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

 let filtrado = watchList.filter(peli =&amp;gt; peli.Director == "Christopher Nolan");

 const averageRating = (filtrado.reduce((acc, item) =&amp;gt; {return acc + ((item.imdbRating)*1)},0)) / filtrado.length;

 return averageRating;
}

console.log(getRating(watchList));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;.filter()&lt;/code&gt; to dismiss any movie that wasn´t directed by my friend Chris &amp;amp; &lt;code&gt;.reduce()&lt;/code&gt; to get the total sum of all ratings together. Then just divide that last number by &lt;code&gt;filtrado.length&lt;/code&gt;. &lt;em&gt;The amount of movies directed by my friend Chris.&lt;/em&gt;&lt;/p&gt;

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