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 bad, it has a time complexity of O(n^2), but for a fixed array size it's just fine.
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 didn't see the replies until your comment Andrew, but now that I come back to it I don't see why it would break for long words. I think I saw indexOf and thought charAt or some such thing. I don't know, this looks like it works to me.
Also I don't get the FUD about using regex, they're not slow in general. Some regex can be slow, but one that looks for a single digit is as fast as indexOf.
@prohairesis Give it a check, the function indeed breaks for really long words.
This comment is hidden because it contains spoiler information about the solution
Is there a way to make it O(n) without the use of regex?
Nice work @RafaWilinski. I think as you advance, you will realize that nested for loops are inefficient for larger data sets.
That is not true. He is not looping through each letter intentionally. The test case you provide, "longlonglongword2 hello1", would still pass. He does not need to loop through each letter, he is using .indexOf on the entire word to find the index from the outer loop contained within the ENTIRE word. If not, continue looping until it finds it. Once it finds it, push it to result.
This comment is hidden because it contains spoiler information about the solution
lol I did the exact same code.
totally what I did... just different variable names lol...
Great code! - but it seems like you made an error in your inner for loop. Your limit is the length of the array, but it looks like it should be the length of the string that you are looping through at array[i] -ie. j < array[i].length?
that was boody smart mate
Loading more items...