Ad
  • Default User Avatar

    Don't bother to answer to this unless you wan't to help others having similar issue, because I already managed to submit a suitable solution.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Hi,
    Thanks for the comprehensive explanation and answer. I already managed to complete this Kata using a different approach to the problem.

  • Default User Avatar

    Hi Samuq

    There are quite a few optimizations you can do here. Lets for arguments sake say that str2 is of length 1000 and str1 length 100. This is very conservative numbers because the strings I use in this kata are huge. So for our example, we can see that:

    1.) every is O(n). This means if we have no code to run inside the callback, it will execute 1000 times. But we do have code in there, so lets go deeper.

    2.) So inside every, you are doing indexOf. This operation is also O(n). This means if we had did indexOf only once, it will iterate over every char in str1. This will be 100 times.

    3.) splice is another O(n) operation. With splice, it will remove an element and then re-index the entire array. In order to do this, it needs to run over all the elements in the array. In this case, it will be 100 times.

    So conservatively, we are looking at 1000 x 100 + 1000 x 100 operations for small str1 and str2. You can see how this can blow up.

  • Default User Avatar

    I have the same problem..

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    I have the same issue. I wonder how can I optimize more..