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.
Sadly JavaScript doesn't use integers, so this solution will fail if you give it a value of
0.12
.Test cases was fixed a year ago.
This is the clerverest.
how did you deduce the quadratic equation based on the table?
i am not able to figure out that
Nice solution - thank you.
Maybe you can replace the last three lines of code with
This comment is hidden because it contains spoiler information about the solution
If you pass 0.5 to the function, it won't return the negative value;
f.trim(); would also work in this case - I find it easier to read than substring, though substring is more efficient probably.
Lambdas are not slow. This solution is O(n^2) due to string concatenations (not O(n log n) as another user said), but n is constrained to a very small constant, so the solution is fine. If n was unbounded, the best way to improve this solution would be to use a StringBuilder to concatenate the strings. This would result in a total time of O(n log n) (the time to sort), which is very good.
This is very clever, but how in the world is this a best practice? It's barelly readable!
I don't think it's slow because it's lambda. Correct me if I'm wrong, but it will replace the string every comparison. That's O(n log n) replaces, instead of the usual n.
The best way to figure the problem out mathematically is to make a table of the values and find some patterns, although I did need to use cubic regression on a calculator...
#Calc
I like the f.substring(0,f.length()-1) part. Never thought of it I am going to now use it more often.
Kudos for lambdas :)
Whats the math behind this?
I think this would fail if the kata ever had more than 10 words since you're using String's compareTo rather than Integer's.
You are right, though its always intresting to insert a new solution! This gave you a chance to cricically compare and its learning for all of us. Thanks!
Loading more items...