Technical Blog Part 5. Problem Solving

<ul> <li class="question">A story about getting blocked on a simple problem and solving it problem in an elegant way.</li> <p class="answer"> I was blocked on exercise # 3 from Eloquent Javascript book, Chapter 2. The task was to create a string that represents an 8×8 grid of symbols ("#"). I couldn't figured out how to apply loops and to link if/else statement to decide to put a space of a hash sign. I wrote preudocode, but it didn't help me. After trying different approaches, I googled and found out about String.repeat() function that I easily applied and the problem was solved.<br> What I learned from this case is there are multiple ways to solve a problem, and if you are blocked with one method, you need to think out of the box, and try different approaches, the ones you probably even haven't considered before. </p> <li class="question">How confident do you feel using the problem solving techniques and process?</li> <p class="answer"> <ul class="post-10"> <li> Pseudocode really works for me, as in fact it is a plan of actions, and gives the structure to the future program.</li> <li> Reading error message sometimes is helpful too, even though I tend to ignore them..</li> <li> Console.logging and Googling are probably my helpers # 1 at the moment.</li> <li> I haven't tried rubber ducky method, but I think I will one day.</li> </ul> </p> <li class="question">Explain .map(), .filter() and .reduce() functions. </li> <p class="answer"> <ul class="post-10"> <li><b>.map()</b> function helps you to create a new array, and new elements in this array will be a result of a function you applied. Let's imagine you had a bowl of apples (this is an array), and you baked them (i.e. applied a function), once you took your baked apples from the oven and put them into a bowl you got a new array.</li> <li>with <b>.filter()</b> method you can create a new array, which will contain only the elements that passed certain requirements determined by a function. So.. coming back to our apples. This time you have a bowl with green and red apples (meaning your initial array). Now you want to <em>filter()</em> them, and you take out all green apples, leaving only red ones in your bowl. You just got your new array!</li> <li><b>.reduce()</b> method converts your array of many elements into a single value by applying a function to each element. This time you have a bowl with apples, sugar, flour, butter and cinnamon. You apply a <em>reduce</em> function, which mixes (sums up) all your ingredients (elements), bakes them, and as a result you get apple crumble (just one single element).</li> </ul> <div class="apple"> <p id="clickhere">CLICK HERE</p> </div>

User's comments

Add a comment