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 doesn't seem like the most practical approach.. don't know why it has most clever votes..
I really dig the way the alphabet array was created here.
Yes, I did exactly what you say ,But in a more stupid way
if the specified substring ( a - z ) is not present in the given value ( string ), the indexOf() returns a negative value.
.
Theoretically, it's true
But in practical...
Yes, something that runs in
26n
is 26 times slower than something that runs inn
.However, when talking about big O notation, that doesn't make a difference. There exists a C>0 for which they are both always faster than
C*n
. This means that by definition, they are both part of O(n).This is why big O isn't always the be all end all. It's applicability always depends or your application. If
n+26
would run in a day,26n
would need 26 days, but an^2
algorithm could very well need a year to accomplish the same and2^n
could take a millennium.If you compare something up to infinity, "26 times slower" is insignificant and can be neglected.
Oh I see,
but still O(26n) is much worse than O(n+26)
No it isn't.
indexOf
is called a fixed amount of times. The length of the alphabet does not increase when the input length increases.In terms of big O notation, this has the same performance as basically all other solutions: O(n).
BAD Performance
This comment is hidden because it contains spoiler information about the solution
Is the "x" value looping through all the letters from a to z and inside the every method it tries to find a letter that matches the "string" variable? If it finds a match then it returns the position of that letter and if it doesn't find a match then it will return -1? Also can I get feedback on my solution and let me know if there is anything I could improve?
This comment is hidden because it contains spoiler information about the solution
I'm new at this but I've been told the goal is to write code that legible to others. The idea being you'll (theoreticly) be working with other programers and they'll need to be able to follow your code and tell whats happening. That said, is it bad form? No clue. But I do think that the original answer by marutiborker is more easily followed than the long one-liner format.
Loading more items...