Trouble with JavaScript algorithm scripting exercises

Hey. I’m quite diligently following the course of JavaScript Algorithms and Data Structures from I can do almost every exercise but when it comes to the algorithm scripting part I’m quite clueless about what I should do and how can I fulfill the task. After a lot of brainstorming I finally resort to the solution and get it done. Can anyone please guide me how can I pass this stage as this is making me scared that I might have made a wrong choice by skipping my job and investing my time in learning something that is really not for me. Any advice please.

You are the first person ever to not instantly understand algorithms. They’re so easy. Oh, no, wait, the opposite of that. They can often be quite hard and confusing for beginners. Nearly everyone struggles with them. Relax, cut yourself some slack and be proud of what you’ve accomplished so far.

First of all, let me set down a couple ideas.

  1. Algorithms are an important part of coding.
  2. Algorithms are not the only thing in coding and is not even the most important.
  3. Many coders don’t encounter a lot of difficult algorithms. (In my 3 years as a developer, I’ve probably only don’t 2-3 things I would consider even an intermediate level algorithm.)
  4. Interviewers love algorithms because they are easy to evaluate and (they believe) that they give them in insight into how you think and how you approach problems.

Why learn algorithms?

  1. They can come in handy and sometimes they are life savers.
  2. They teach you different ways to think.
  3. They are a great way to impress interviewers.

That being said, I think algorithms are important, but I also think that a disproportionate weight on them.

How to learn them?

Like I said, I think it is about learning how to think differently. If I asked you to sort a list of numbers, you could do it without thinking much. You use an algorithm, but you just don’t think about it that way. How would you explain the process to a computer, that has no concept of sorting? They “understand” what it means for a number to be higher or lower, but doesn’t know how to apply that to a list of numbers to sort them. You have to learn to think like that.

I think it is like a muscle - the more you do it, the stronger it gets.

I also think of it as a “bag a tricks”. Each algorithm you learn gets added to your bag. You learned a bubble sort algorithm? That gets added to your bag of algorithms you understand. That also exercises your brain so that similar algorithms will be easier.

Just keep at it. It doesn’t matter how many times you fail or how long it takes - just work it.

After you solve an algorithm, go and see how other people solved it. Maybe watch some youtube videos of people breaking down algorithms. (The computer language used doesn’t matter much - algorithmic thought is language independent.) If you end up “cheating” and looking (please avoid), maybe wait a week and see if you can solve it from memory - that you learned it is much more important than how you learned it. (But if you figure it out on your one, that would be better for you.)

And for the record, I’ve known some excellent programmers that weren’t particularly good at algorithms. There are a lot of dev jobs out there that don’t require any deep algorithmic knowledge. And there are some jobs that require a lot, depending on what you are building.

… this is making me scared that I might have made a wrong choice by skipping my job and investing my time in learning something that is really not for me.

OK, that worries me a bit. If you need money, keep your job. It can take a lot of work and a long time before you’re employable as a developer. After finishing FCC, I spent another year just learning other stuff and building increasingly cool things before I started to get nibbles. #ymmv

If you need money to live, then work your job. You’ll never get that dev job if you are homeless and starving.

All in all, just go easy on yourself. This is hard stuff. It takes a while to learn the basics and it takes even longer to get good. Be glad that this is hard - if it wasn’t then high school dropouts could learn it in a few months and it would pay very little money.

1 Like

Hi @salmanabbas !

Welcome to the forum!

Learning how to solve algorithms is a new skill that takes time to learn.

My advice would be to think about the problem and solve it away from code first.

I think most people that start learning algorithms for the first time dive straight into the code before really understanding the problem. Then they have a huge mess in the code and it is a frustrating process.

Think about how a human would solve the problem and then write down the steps in english on how you solved it.

Then slowly turn those steps into code.

With enough practice, algorithm challenges will become easier to solve. :grinning:

I would also advise you to have MDN docs open when you are going through these challenges.
There are a lot of string and array methods that come in handy to solving these challenges.

I agree with @kevinSmith that if you are in need of money, then please work your job and learn to code before and after work.

There have been plenty of developers that had worked full time while learning to code.

If you are able to get a full time job, while you are learning I think that would be your best option.

Hope that helps!

1 Like

To be honest I wasnt really expecting such a profound answer. I’ve just joined this community and really glad to see that it contains people like you who’re ready to write in these great lengths to help someone in distress.
Anyways I was really worried that I just got in to the basic algorithm portion of my Javascript course here in FCC and it felt like I dont know shit because these are just basic algorithm according to FCC but still they felt so hard. But yeah I’ll practice hard now.
Moreover dont worry, I’m 25 and living with my parents(its common here in Pakistan). And I felt like it will be easier for me to learn if I skip my geo-informatics job that was not promising a great growth rate. Well I’m not starving but I set myself a deadline of 6 months since I left my job. Its been 3 months of learning plus I’ve also studied these courses during my engineering degree but there I was more busy in extra curriculars so I didnt go in much depths. But yeah I hope things do turn out good at the end. Thank you so much Kevin.

1 Like

Well I skipped my job because I used to go out for office at 8am and got back home not earlier than 6pm daily. So I thought by leaving job I would’ve far more time to learn development. And yeah I’m not in dire need of money but it has been 3 months and I’ve started to feel like I’m burdening my parents a little too much. It was time for me to give back what my parents have done for me and I’m taking no use of my engineering degree. So I need to learn it a bit faster but the algorithm portion really troubled me alot and I went depressed about all the choices I’ve ever made in life. Your advice and kind words were really motivational and I hope I can soon gear up my skills to find a dev job.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.