How can I get better at JavaScript algorithms?

How can I get better at JavaScript algorithms?
0

#1

I’m looking to get better at algorithms. I’m struggling with the algorithms challenge and have yet to get one completely correct without looking at the answers. I’ve been advised to start practising math problems and playing chess etc. but I’m not sure where to start. Thanks in advance.


#2

I suggest not peeking - instead ask questions about a specific problem on the forum - you will get hints and suggestions for every stage right from how do I start tackling this problem


#3

First, break down the problem into smaller problems (try to go as small as you can conceptually). Naturally, it helps to know what is available in the language (if this is for FCC algorithm challenges, they usually give hints as to useful methods and functions in the sidebar).

Then, try writing the whole process out. You can do this in steps:

  1. Flowchart
  2. Pseudocode
  3. Real JavaScript

The only step you’ll need to worry about syntax for is step 3. Once you get to that point, it will be a lot of Googling: for example, Googling split string into array every space js will help you find exactly what you need (the split() string method).


#4

Just check these algorithms solving sites:

Hope it would help


#5

I’l make sure to look into them right away. Thanks.


#6

Thank you. I’ll do my best to keep this in mind.


#7

as above. do it urself. dont worry, algo’s take a LOT of time.
maybe run codecademy js another time. i did both js and jQ there 2 times. or do the codeschool stuff. it has lots of js, and i thought it to be very good.


#8

I think one of the most important things, like others have said, is to break the problem down into smaller parts.

WHEN you do this, see if you can identify what you really understand and can solve, what you kinda understand, and any parts that are new concepts that you have never been introduced to.

I went through a 9 month bootcamp and wasn’t really exposed to algos, and had trouble solving the most basic code wars problems.

I had a horrible whiteboarding session where I embarrassed myself and the next day started from square 1 with bubble sort and basic recursion. I spent several days watching tutorials, memorizing how the code was written in those tutorials and writing them from memory over and over again, while reading the code aloud to myself.

Doing this had an unintended but welcome benefit. My mind started to to think logically, mathematically, and I was able to reason about and solve problems I had never seen before.

I don’t know what your math background is, but mine is weak. Almost failed Algebra 1 and 2 in HS and scraped by in College Algebra and that was back in the 90’s, early 00’s.

I had a flabby math brain that wasn’t dumb, it was just out of shape and had never really been to the gym.

I guess what I’m saying is that if you keep at it, you get it Even just the fact that you are here seeking help means you are in the process of transforming your brain and learning aptitude.


#9

Thanks for the advice. Do you by any chance have any videos in mind?


#10

Did you ever manage to find any videos related to solving algorithms even the most basic ones or even websites because im literally struggling on the same exact issue at the moment


#11

You’ll find videos and resources on specific ways of solving most of them (particularly the maths-related ones), as most are either common problems or variations of common operations (see http://rosettacode.org/wiki/Rosetta_Code)

Also, because almost all of these are standard problems, it’s very easy to find out how other people have solved them. And because there is no one answer, you can try them over and over again.

The major issue is is that the core thing you’re looking for is literally “how do I do programming”. The algorithms section provides you with isolated practise problems that you can try over and over again regardless of skill level. In the real world you might need to do something similar, but it would be a [small] job on a part of a larger system.


#12

thanks for the advice given, i tried opening up the link you gave but it wasn’t opening for some reason


#13

Something in your browser stopping it (though I’m not sure why)? Google Rosetta Code anyway.

But don’t worry about not being able to do the puzzles at first - don’t feel bad about looking at how other people have solved them. But if you do, just [and this is really important] make sure that you understand how those solutions work. For things like finding prime numbers, there are very well understood mathematical solutions. Wikipedia is your friend here: there will normally be pseudocode/Python/text examples of possible code solutions, which you can learn to convert to JS.

Use the documentation (MDN, primarily) as much as possible - if you see someone else’s solution, and they use some JS syntax/method that you don’t recognise, look it up, learn why it’s used, and make sure you understand how to use it in future; use it as an opportunity to learn.

As I say, almost every one of these challenges have no one solution, so you can go back and try them over and over using different techniques: the tests only check you produce the correct answer, they don’t check how you get that answer.

Edit: just as a bit of background, why this technique is popular for learning and kinda the reason this section is the way it is, is summed up here: http://codekata.com/. The links section is great, and overall, this quote I think is the best takeaway:

Remember that the point of the kata is not arriving at a correct answer. The point is the stuff you learn along the way. The goal is the practice, not the solution.

And

So, my challenge for the day: see if you can carve out 45 to 60 minutes to play with a small piece of code. You don’t necessarily have to look at performance: perhaps you could play with the structure, or the memory use, or the interface. In the end it doesn’t matter. Experiment, measure, improve.

So don’t worry: use each run you have at one of the challenges as an opportunity to learn a technique, try a different way of doing things, improve your code style, whatever


#14

Thanks for the advice and i’ll defo look into this 100 percent. Ill check the website out too.

Thank you