Home Problem Solving

Problem solving

A time I was blocked on a simple problem

The problem I faced is one of my own design. When learning about slice and splice for my method research I would go through learning what each method did. The problem was that I would try to get through and finish my work and in doing so would gingerly skim through some of the descriptions. This caused me to not notice that when running the test, it gave results that actually didn't align with what I was trying to do. See the below my problematic code.


  let fruits = ['banana', 'apple', 'orange', 'kiwi', 'grape']

let sliced = fruits.slice(1, 3,)
console.log(sliced) //[ 'apple','orange']
console.log(fruits) //[ 'banana', 'apple', 'orange', 'kiwi', 'grape']

As seen above you can see my original slice that has the parameters of taking 1 and 3 and removing them when calling for a slice. When returned, I received 2 fruits. I didn't even think twice as I had passed the test in that the function worked. Those with a good eye may have noticed I asked for 2 changes, and it returned 2, However what I didn't notice is the fruits that were returned, were not the fruits in the array I wanted. I wanted 1 and 3, which should of been 'apple' and 'kiwi'. This was thankfully pointed out to me by a fellow home group homie Matt! So I went through and wondered why.

How did I solve it?

The problem here was not that the function wasn’t working so to say, but it wasn’t working how I thought or intended it to work. So I went through the rubber ducky method, which involves going through and talking about each step as though talking to a “rubber duck”. This can help you identify mistakes, however for this issue the mistake wasn't the problem solving method, as I talked myself through it I found no issue. So I went to the next problem solving method, using an LLM to explain to me why it isn't working. I was informed that although I did indeed ask for 1 & 3 to be sliced, the function does not work that way, and in fact works by taking items 1 through 3, but not including 3. So while I was getting 2 fruits back, one of those fruits was number 2, when my intention was to remove number 3. This made me realise my mistake, that I should take my time when reading through material to ensure I'm understanding the details.

Can I use problem-solving techniques?

Pseudocode

I feel comfortable using pseudocode, as it is a technique I use in my head generally anyway when going through a problem, breaking it down to smaller components and what I'm trying to achieve with each step. Trying something I am comfortable (and already have some plan) to try something, to give it a crack and discover how it should work and function.

Rubber ducky method

As in the example above I feel comfortable talking myself through the problem to see if I catch something out.

Reading error messages

I feel pretty comfortable although I do need to improve my syntax and what each word entails. With my own experience of reading error messages largely stemming from video games and overloading them with mods.

Console.logging

I think I could do some more practice with console.log, but I feel pretty comfortable using it.

Googling

A timeless classic, when in doubt, google! But always checking how I google, where the information is coming from and is it applicable to my situation.

Asking your peers for help

I have already asked for help from my peers, and with our homegroup we have organized in previous weeks a weekly meetup to discuss our confusions or problems we are experiencing, and to get guidance from our peers.

Asking coaches for help

I have yet to really utilize this, but I do feel comfortable that if a problem would occur that any of the previous methods could not solve or assist in, I would happily go to a coach for assistance.

Improving your process with reflection

I do mentally reflect on how I made a mistake and what I could do to ensure I cover my bases to improve in the future.