Writing more concise functions?

Hello!

So I just finished the Basic Algorithm Scripting section and had a blast.

After solving each problem, I looked up the solution to see how others had approached it, and I would see solutions that would be done in 3 to 4 lines, compared to my 8+ lines.

I would like to be able to write more concise functions. All my answers have usually been both basic and verbose.

Anybody else have this experience? Any advice on how to be more streamlined?

I’m guessing it just comes with time and exposure to lots of practice problems.

Any thoughts on this would be appreciated.

Have a great day!

2 Likes

Hi @josephylee

As you avancing in your JS knowledge you could back to those solutions and see if you can solve it differently. But the most important part is get the solutions!!

Make it work and if you get the time make it easier to read and more efficient. One line solutions no always are the smarter solution for a team or company.

I even try to solve farther challenges with basic syntax, I think that push my solving problems skills. So not worries. I had to check some hints and even solutions, so your doing really great!!!

If you have problems to understand some methods you can will use your basic skills to build your own methods (functions) with the same functionallity that map, reduce, etc… It help me. :smile: :sweat_smile:

Keep the good work!!

3 Likes

Writing simple or elegant solutions takes practice. The first step is writing solutions that work.

3 Likes

It is a lot like verbal eloquence. It’s hard to be eloquent about a subject matter you have little knowledge about or when using a language you are not fully fluent in.

As said, it is just a matter of time and exposure to code and the language.

4 Likes

Keep in mind, short is not always the best approach, or more concise, especially when you expect your code to be reviewed and used by other devs, its ok to be a bit more expressive in your code execution and naming conventions. And as you prolly already figured out, writing cleaner code takes practice.

4 Likes

Love these responses. What a great community.

2 Likes

It’s so ironic that I stumbled onto this post

I’ve just been googling

“Feel like my answers look dumb on free code camp”

I am happy to get the problem solved but when you see the “official” solution you almost feel guilty for not remembering the last 25 lessons you’ve done :joy:

2 Likes

Keep in mind, those aren’t ‘official’ solutions. They are just ones that we have checked to make sure they work.

2 Likes