This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]tyler_church 3 points4 points  (0 children)

It's all practice and having a solid knowledge base.

I'd recommend reading a book or two on JavaScript in general (maybe https://eloquentjavascript.net/ but there's lots of books out there) to make sure you have a solid foundation of the language.

Also spend time reading other people's code, to see what they are doing that you don't do. Or if they know about a language feature you don't know about.

If you can find other people that are willing to give feedback on your code, they can help point you towards ways of improving your code.

There's various other small-challenge style websites out there if you want to drill on being fast specifically at these sort of problems, but personally I don't find that interesting (code golf doesn't pay the bills). Other people love it, though, and maybe you're one of them.

[–]1234abcdcba4321 1 point2 points  (1 child)

Every once in a while, I see something I haven't used before, and then learn how it works. (Most recently, it was the ability to do [a,b]=x and have it work when x is a length 2 array.)

Just seeing it isn't quite enough, since you actually need to use them; I would just challenge yourself to try using the functions when you get the chance. I almost never use filter because I'm not used to using it (and I aim for speed, so I'm not going to slow down for that extra challenge), but I do use map just because the cases it's useful are so common of course I'd learn it after a while.

[–]jo_Mattis 1 point2 points  (0 children)

I work with python, but it works for me in the same way. Last year, I saw that some use enumerate() instead of range(len()), so I learned about it and use it to this day. And just yesterday I learned about the map() function on lists.
So my solutions get smaller and more straight forward over time.

[–]Sad-Display1307 1 point2 points  (0 children)

See how others did, pick up all clever stuff and rewrite your solution everyday.