Kowhai

Technical Blog Part 5. Problem Solving


  • A story about getting blocked on a simple problem and solving it problem in an elegant way.
  • 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.
    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.

  • How confident do you feel using the problem solving techniques and process?
    • Pseudocode really works for me, as in fact it is a plan of actions, and gives the structure to the future program.
    • Reading error message sometimes is helpful too, even though I tend to ignore them..
    • Console.logging and Googling are probably my helpers # 1 at the moment.
    • I haven't tried rubber ducky method, but I think I will one day.

  • Explain .map(), .filter() and .reduce() functions.
    • .map() 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.
    • with .filter() 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 filter() them, and you take out all green apples, leaving only red ones in your bowl. You just got your new array!
    • .reduce() 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 reduce function, which mixes (sums up) all your ingredients (elements), bakes them, and as a result you get apple crumble (just one single element).

CLICK HERE