<?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: Lauren</title>
    <description>The latest articles on DEV Community by Lauren (@laurenlucero).</description>
    <link>https://dev.to/laurenlucero</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%2F339669%2F7fd4d393-abbf-4f0e-9f44-bff707a8f77c.jpeg</url>
      <title>DEV Community: Lauren</title>
      <link>https://dev.to/laurenlucero</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/laurenlucero"/>
    <language>en</language>
    <item>
      <title>Be a Problem Solver Challenge!</title>
      <dc:creator>Lauren</dc:creator>
      <pubDate>Fri, 21 Feb 2020 18:10:39 +0000</pubDate>
      <link>https://dev.to/laurenlucero/be-a-problem-solver-challenge-1a41</link>
      <guid>https://dev.to/laurenlucero/be-a-problem-solver-challenge-1a41</guid>
      <description>&lt;p&gt;Challenge yourself to solve problems you've never seen before with this step-by-step guide to being a programming problem solver!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Choose a problem to solve.
&lt;/h2&gt;

&lt;p&gt;Try Codewars.com or Google 'coding challenges'. &lt;/p&gt;

&lt;p&gt;I had the opportunity to engage in the problem-solving process with a partner as a student at Turing School of Software Development and Design in Denver. If you can work with a partner, do it! Two brains are better than one. I learn the most when I can talk through my ideas and hear how someone else thinks about the same problem. If you don't have a partner, talk to yourself. Seriously, it will develop your understanding and vocabulary if you talk through a problem before you attempt to program it.&lt;/p&gt;

&lt;p&gt;Our instructor gave us some challenges to choose from and we chose Counting Sheep. &lt;a href="https://www.codewars.com/users/sign_in"&gt;CodeWars&lt;/a&gt; is a good place to find challenges. Our challenge was to write a function that takes an array of Booleans. This function should return a Number that represents the number of times that true was present in the array. &lt;/p&gt;

&lt;p&gt;This was the example:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var sheep = [&lt;br&gt;
  true, true, true, false,&lt;br&gt;
  true, true, true, true,&lt;br&gt;
  true, false, true, false,&lt;br&gt;
  true, false, false, true,&lt;br&gt;
  true, true, true, true,&lt;br&gt;
  false, false, true, true&lt;br&gt;
];&lt;br&gt;
countSheep(sheep);&lt;br&gt;
// =&amp;gt; 17&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Don't start typing!
&lt;/h2&gt;

&lt;p&gt;Psuedo-code and make a plan for how to solve your problem on paper or a whiteboard. Brainstorm a detailed yet readable description of what a computer program must do written in natural language rather than a programming language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g0RJQS2l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wiqzab3jui0jko86es28.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g0RJQS2l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wiqzab3jui0jko86es28.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This whiteboard shows how my partner and I made sense of the problem initially and our ideas for our third possible solution (see step 5)!&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Do any research on the tools you'll need to solve the problem.
&lt;/h2&gt;

&lt;p&gt;My partner and I started by Googling 'check all elements in array javascript' and 'check each index in array javascript'. We didn't find any methods that would return a number. My partner thought to use a counter variable and a for loop to return the sheep count. We talked through the code and jotted it on our whiteboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Implement the solution in a programming language.
&lt;/h2&gt;

&lt;p&gt;We only started programming after building a strong understanding of the problem and an idea for a solution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countSheep(sheep) {
  var sheepCount = 0;
  for (var i = 0; i &amp;lt; sheep.length; i++) {
    if (sheep[i] === true) {
      sheepCount += 1
    }
  }
  return sheepCount
}
countSheep(sheep);

//return 17
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We did it! But we wanted to strengthen our problem-solving muscles even more so we continued to step 5 of the process...&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Challenge yourself further by trying to find another solution to the same problem.
&lt;/h2&gt;

&lt;p&gt;After success with a for loop, we came back to trying to use an array prototype method. We perused the list of methods on &lt;a href="https://developer.mozilla.org/tr/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype"&gt;MDN&lt;/a&gt; and read more about any that seemed like they would work based on their name.&lt;br&gt;
Our second solution used the .filter() method to filter true values from the sheep array into a new array then log the length of our filtered array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function equalsTrue(value) {
  return value === true
}

var filtered = sheep.filter(equalsTrue)

console.log(filtered.length)
//17
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We continued to challenge ourselves to find one more solution. This time we used .sort() and .splice() to sort the array alphabetically then remove the first values from the sorted array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sortedSheep() {
  sheep.sort();
  if(sheep[0] === false) {
  sheep.splice(0, 7)
  }
  return sheep.length
}
//return 17
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though our additional solutions weren't the most intuitive, we learned more about programming through dialogue and practice!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is this important?
&lt;/h2&gt;

&lt;p&gt;Programming is problem-solving. If you want to get better at anything, you have to practice! Try problem-solving using these steps, comment about how it went and what you learned! &lt;/p&gt;

</description>
      <category>productivity</category>
      <category>challenge</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
