Problem Solving Blog

Problem Solving Blog

A time when I was blocked on a simple problem

What was the problem

The simplest problem I encountered was figuring out where to actually write my answers.

What problem solving techniques did you use?

I just kept trying until I grasped what was happening. Eventually I saw the tests for each individual kata (1, 2, 3, 4, 5) and I used this to check what I was doing

How did you feel throughout the process

I was very frustrated for a long time, I think taking a step back to look at all the resources I have at my disposal before jumping into exercises will really benefit me.

What did you learn

What I learned was to use the resources I have at hand better. Also I need to read everything. For the last exercise deBee I didn't read where it said to split which took me off on a completely different tangent trying to find source material to learn how to use .replace. I do enjoy things like this though as it exposes me to different solutions to problems.

Elegantly solved a problem

What was the problem?

I don't know if I can really call it elegant but I am pretty proud of it. My solution for the final deBee challenge used a different method than what was recommended and it actually works with only three small lines of code.

What problem-solving techniques did you use?

There was a large amount of googling for this. I think I had four different tabs open dedicated to trying to figure out what I am trying to do. I also used pseudocode to break it down into smaller steps. This helped a lot, at one point I had removed buzz and buzz with any form of capitalization but the string returned had all these spaces in it so the second test wasn't passing. I then had to research how to remove additional spaces from a returned string. The process looked a bit like this, with my pseudocode being the test pass or fails from the npm.

// returning a string now. [✓]
// make the string return where word buzz has been removed [X]
// make the string return where word buzz has been removed, regardless of captialization [X]

function deBee(sentence) {
return sentence}

Then I had to google how to remove a word from string and I stumbled upon this site here which showed me how to use .replace to search for words and replace them with '', or nothing. After this I was almost done and had something that looked like this:

// returning a string now. [✓]
// make the string return where word buzz has been removed [X]
// make the string return where word buzz has been removed, regardless of captialization [✓]

function deBee(sentence) {
return sentence
.replace(/\bbuzz\b/gi, '')
}

the \b is a word boundary anchor which shows where the word starts or ends, thinking back maybe I could use this and have something like \b" " + buzz + " "\b to remove the spaces. Could be cool if it works. The /g is a global flag which just means it checks everything for buzz, and 'i' makes it ignore case so will match both uppercase and lowercase versions of buzz, eg:

Still not complete though as the second test wasn't passing and when I looked at why I saw this:

- Expected
+ Received

- Help! I'm surrounded by bees!!
+ Help! I'm surrounded by bees!!

So I had successfully removed buzz and Buzz and any form of capitalized buzz but not the blank spaces left by the words or at the start and end of the string.

This led me Here and showed me how to replace multiple spaces in a string with one single space and also the .trim(); to remove spaces at the start and end of a sentence and left me with this:

// returning a string now. [✓]
// make the string return where word buzz has been removed [✓]
// make the string return where word buzz has been removed, regardless of captialization [✓]

function deBee(sentence) {
return sentence
.replace(/\bbuzz\b/gi, '')
.replace(/\s+/g, ' ')
.trim();
}

With all tests passing

How did you feel throughout the process?

Incredibly frustrated at times. I am still not very good at console logging anything. So I relied on the npm to help see if what I was doing was working, which probably added a lot of extra time to the process. In saying this though, I feel very accomplished.

What did you learn

I learnt that there are multiple ways to solve a problem and that I should learn to read better. No but in all seriousness I learnt that I can figure out how to solve problems with the little knowledge I have through problem solving techniques. One thing that I am really glad I figured out is how to add properties to the value of other children properties. I struggled for a long time writing huge multi lines of code to try get this to work to then figure out that it is one simple line, this was a theme throughout the whole challenge.

Reflect on how confident you feel using each of these problem-solving

techniques/processes:

Googling is probably my best problem-solving technique which I am not too happy about. I am also confident to just try something and then figure it out from there. Areas I need to improve on would be googling less and being more willing to reach out to my peers and instructors for help.

Reflect on a time you were reluctant to ask for help.

Consider what made you reluctant to do so.

What might you try differently next time?

I think it is something I struggle with on a broader scale. I see people posting their blogs days before me and being already finished with the Kata and it makes me shell up as I feel that I am way behind. Next time I'm just going to send in whatever I need to.