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.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I solved it this way, knowing that it was probs going to be the top solution (since the top answer is typically the most clever/clean answer, not always the most efficient). That being said, I've never flip-flopped my oppinion about my answer so many times while reading a discorse on codewars before... lol. It's 8kyu and we're all overthinking the crap out of it.
I would say this is best practice since it is easier to read and understand.
The
if
solution is more likely to be written wrong or get misunderstood.Yes, you must be right. Thanks for your feedback.
You've spent more time writing that than we've thought about the problem.
Performance is a mechanic to consider for your task, and in this context when our goal is to solve a self contained problem with implied constraints, if it's fast enough to pass the test cases, it's the best practice.
You can argue about O(1) vs O(2) all you want, but quite honestly it's javascript we're talking about here and the engine is better at running fast code than you are at writing fast code. Go use C++ or something.
Awesome!
No problem, I revisited my first solution and it mutated the input too ;). Refactored it to make it pure now.
Lol you just edited your comment as the time I write the reply ^^
In French we say "Les grands esprits se rencontrent".
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Nice. A plus could be to move the two constants outside the function, so there are not re-created any time the function is called.
Should be upvoted best practice as it does not mutate the input.
You're right, probably better performance.
You made my day
Loading more items...