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.
Should avoid mutating input.
Clever, but not best practice.
length
is updatedNeed more basic tests. Top voted solution does not test for basic cases such as
"?1+1=2"
,"1+?1=2"
and"1+1=?2"
. Both should evaluate to-1
, but top solution evaluates to0
.More random test cases couldn't hurt either.
This comment is hidden because it contains spoiler information about the solution
Ignoring the lack of random tests (and only a few hardcoded tests), this is still not best practice or even that clever.
You don't need all those checks which make the code hard to read.
It is unfortunate that none of the top solutions use algebra to solve this, but all choose a brute force algorithm...
It is definitely a byproduct of the kata requiring the next highest pair for false results.
It is unfortunate that none of the top solutions use algebra to solve this, but all choose a brute force algorithm...
It is definitely a byproduct of the kata requiring the next highest pair even for false results.
It is unfortunate that you require the nearest pair or else there is an elegant algebraic solution.
Basically, it seems like you approached it algorithmically and got a nearest pair from your algorithm, so you just added it as a requirement for the return value.
JS needs random tests.
Not sure why everyone is writing so much code when there are no random tests on a 4 kyu.
Can literally solve the kata in less than a minute without even thinking about an algorithm...
This comment is hidden because it contains spoiler information about the solution
Calling an object literal
arr
...I wish there was a downvote feature...
This comment is hidden because it contains spoiler information about the solution
Your solution loops through twice as well... What's the point of nitpicking time complexity when you are doing the same thing? Your
else
also doesn't need tofind
anything. You already have it inevenValues[0]
. Even with that optimization, your worst case is still n^3 for an array length of 3 and n^2 for other cases.At least come up with a performant solution without unnecessary things before complaining that other people's solutions are "unnecessary and not performant".
This comment is hidden because it contains spoiler information about the solution
Loading more items...