I make sure I design and write my own code in the intermediate algorithm challenges but I think some of my solutions are too long though it eventually works and solve the problem. As a new programmer, am I in the right part?
I’m in the same boat. Whenever I finish an algorithm or project and then look at other people’s solutions I am amazed at how concise their solutions are compared to mine and feel like a rank amateur as a result.
But, I think the purpose of these things is to not just teach you a specific clean solution, but instead to teach the skill of problem solving.
When you get better (and you will) you can go back and refactor them with new things once learned
That completely sounds like the right thing to do. A lot of people refactor code all the time. So once I have completed a challenge I save it, make sure it knows I have passed and then look at how I can improve the code!
It’s better to be coming up with your messy solutions, instead of copying elegant ones made by others. That does not mean that you shouldn’t be looking at others’ code, but I feel that it’s better to do that after you’ve solved a problem, or at least tried for a couple of hours.
If you’re interested in algorithms and writing better code I would suggest solving problems at Hackerrank, CodeChef or CodeWars and looking at the best solutions after you’ve solved them/given your best (although the first two will probably lack in JS solutions) to learn to write clean, efficient code.
in the same time it takes the advanced solution to run 40 thousand times you could run the intermediate solution 550 thousand times or the basic solution 3.5 million times
That’s awesome! Thanks for running the numbers, @P1xt, it helps to dispel some of the myths (that I’ve been constructing in my own head) surrounding higher order functions and the like.
Are there particular cases when these more advanced features are ‘better’? Or does it just depend on what metric you use to define better - such as concision vs performance vs ‘what I know works’ vs composability etc?
That’s incredible. I can read the top one and reason about what it is doing very easily - like ‘day-two-of-learning-JS-easily’!
That second one just makes me want to cry. I mean, I can also reason it out, but I am using a lot more cognitive energy parsing the regex in my head and ternery operator at the end there.
Point very well made!
Thank you for this post.
I tend to get REALLY discouraged when I look at the advanced or intermediate solutions in the Wiki. Especially the ones with the ternary operators, those ones read like a foreign language to me.
I suspected that that’s the case as you said above, but it is still good to hear from someone who’s a lot more experienced.
Thank you for the explanation.
And sorry if I came down negative, you are absolutely right, and that’s why I check regularly the Wiki solutions and other solutions as well after I solved it myself. One can learn a lot from them. The ternary operators and the new ES6 syntax are necessary to learn, a noob can be easily overwhelmed though.
And thank you for all your posts, I always learn a lot from them.
(And sorry OP for hogging the thread, oops. )