Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Not an issue
If you are looking for fastest solution, for loop should always be faster than any Array prototype methods.
A faster Array prototype method for this problem should be a single reduceRight since there is no concat required after as opposed to a filter solution.
Great thanks for the test, my solution was the slowest unexpectedly.
These people are right. You're a horrible person for making this a competition. Here's my entry that ran over 330 million times compared the the 2nd best of 42K.
AMAZING FOR LOOP-POWERED SPEED!!!111!!
Lol.
In all seriousness though, it's only a constant factor improvement. The time complexity of the top ranked solution is the same as that of the rest of ours and it's extremely clear code. I would use filter myself in 99% of work situations and only bust out the for loops and array arithmetic if something needed the optimization. 99% of the time clarity is worth more. I voted up the double filter solution.
This comment is hidden because it contains spoiler information about the solution
Here's my triangle. My method is 100% cheap and obnoxious. Hopefully it's good for a laugh though.
http://www.codewars.com/kata/reviews/52945ce49bb38560fe0001dc/groups/537fb57dc7017521fe001301
This comment is hidden because it contains spoiler information about the solution
What makes a "good" solution also depends on the target platform. Is a "good" solution one that is optimized for the JavaScript V8 engine v3.15, or is a good solution one that is also able to run on older JavaScript versions or one that makes use of the most modern features like those provided in ECMAScript 6? In the real word in client-side programming you usually have to support various JavaScript interpreters of different age each with their own quirks (just think of Internet Explorer). A good solution is one that works on all of these platforms, but it is usually not the most elegant solution.
Interesting phrasing... yes, let's leave 'best' solution to the boffins and just be satisfied with defining a 'good' solution.
To my mind a 'good' solution has three goals:
So in the context of these kata, then creating global vars would violate term 2 above and be judged as 'bad'.
What to optimise for is left to the coder...maybe we should have to state what we're optimising for in each kata?
The [8, Draw!] means that the computers places his mark on 8 and with that, the game ends in a draw. The [0, Draw!] means that all marks are set already, so the computer has no move any more, i.e. the game ended in a draw with the last move of the human.
:) top reply, well done, I withdraw any accusation of making a dick move :)
We kinda need criteria to judge "best"... it's not always performance. In fact, for a vast majority of commercial coding I think readability trumps performance (which clearly this solution fails at too!).
Also, there really is no one "best" solution for a problem, well, real-world problems at least. But at least we can think about finding the best one :)
um, it's not a competition... we're learning here. Trying to make coding a competitive activity is a dick move.
Though mutating a parameter passed as reference is sort of unexpected.
Now I saw it! And yeah, shifting left is definitely a wiser and more performing option for this one! []s
This comment is hidden because it contains spoiler information about the solution