Trouble With Algorithms

Hey folks!

I’m sure I’m not the only one here having trouble with learning algorithm functions. But, that whole section didn’t really seem to explain how algorithms work very clearly. I keep going back to different sections to wrap my head around things, but it still doesn’t make sense. Does anyone have any suggestions as to what I should do to try to grasp this concept better? I checked out the CodeAcademy “Recursion in JavaScript” section, and that helped me out somewhat. Right now I’m just really stuck on the “Check for Palindrome” challenge.

Should I go back through the section and re-do some of the challenges? I’m so stuck with this one, I’m not even sure where to begin, and I kind of wish the section elaborated more on using algorithms and recursion. Things like why we use them, the proper application for nested loops, while loops, if/else vs. switch/case. I think that for such an intense concept, the information was fairly slim.

Help a camper out? (I’m not looking for answers, I’m just looking for a step in the right direction for better understand this) Thank you all!

here’s what I’d do

0 . relax - grab a coffee and snack - keep munching for the next 8 steps
1 . simply read the problem statement and instructions once - no need to completely understand anything
2 . work through any provided examples in your head once
3 . look at the test cases in order
4 . carefully examine the inputs of a test case - how many inputs are there - what is the type of each input - what is the meaning of each input
5 . carefully examine the output and result of a test case - what is the type of the output - what does the output mean?
6 . Make sense of the relationship between the output and the inputs - does it jibe with your understanding of the problem? read and re-read the problem statement till it does
7 . do not solve any test case or the problem in general - the goal is to simply validate the test case against the problem statement
8 . repeat for 2-3 test cases

after completing the steps above you’re ready to approach solutions to the problem

now to work

put the snack down - seriously
grab paper and pencil
we want to approach a solution - not necessarily actually solve the problem since with programming there’s no actual solution till the code works
we just want a preliminary phase - an intermediate stage that will guide us and to which we can return and reconsider when the code turns ornery

write the first test case - use whatever notation you like
e.g. the first palindromes test case is palindrome(“eye”) should return a boolean

ok - that’s stupid
write the second test case - palindrome(“eye”) should return true - this is what I’d write

eye -> true

the idea now is to describe a solution in everyday language - no code - no variables - no arrays - no loops - no lambda combinators
pretend you’ll need to explain the solution to a fifth-grader - from 100 years ago - before fifth-graders used to write facebook apps

while we want to avoid programming terms at this stage we do want to be as precise and most importantly as deterministic as possible
we want a solution with instructions that are repeatable no matter who or what follows them
it’s just that our early instructions will be in ordinary english given to the hypothetical fifth-grader

1 Like

I’m sure I’m not the only one here having trouble with learning algorithm functions.

Oh, good god, no!

Some people “get” algorithms pretty easily, and some have to work hard at it. And there’s a lot of gray areas in the middle. But maybe that just means that some other aspect of web design/development will be easier for you. We all come to this with different strengths and weaknesses.

But algorithms are pretty important. It’s just a different way of thinking. How do you sold a problem with a limited number of commands. You have commands to assign variables, manipulate data, control program flow, (like for loops, if/then/else, etc.)

FCC is not meant to be a complete course. It is expected that you use some outside resources for areas where you need extra work. I might suggest checking out youtube videos. When I search for “algorithms for javascript” a lot of videos pop up. Search through them, work your way through some problems with them,

But ultimately don’t get discouraged. And don’t be afraid to ask the forum if you get stuck on one or even if your not sure you understand something you “solved”.

Thank you all for your kind and very helpful advice. I managed to get through the Title Case A Sentence challenge. It took me a couple hours of frustration, confusion, and maybe a few tears, but I got through it. And my code is concise. Thank you all again for the help! <3

function titleCase(str) {
  var newStr = str.toLowerCase().split(' ');
  for (var i = 0; i < newStr.length; i++){
    newStr[i] = newStr[i].replace(newStr[i][0],  newStr[i][0].toUpperCase());
    
  }
  newStr=newStr.join(' ');
  return newStr;
}

titleCase("mOcKiNG sPonGEbOb mEmE");

Thank you kindly! I will keep that in mind for future posts. :sunglasses:

that looks pretty good - you took the ball and ran with it

Good job. Just keep working that algorithm muscle and it will get stronger.

I remember looking through some old forum posts where p1xt recommended one to take a detour and go through ydkjs and cs50. By the time I went to cs50, I was more than halfway done with the intermediate algorithms but I agree with her advice. Freecodecamp doesn’t really teach you much more than syntax for JavaScript. Going through cs50 for a bit will help you to develop the problem solving skills for the algorithms and projects on freecodecamp. Personally, for javascript I would recommend something like Understanding the Weird Parts first since it’s easier to understand them going through ydkjs after.