Ad
  • Custom User Avatar

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

  • Custom User Avatar

    This is such a helpful and clear explanation of this solution. Thank you for taking the time to write this out!

  • Custom User Avatar

    Newbie question: how do you know or find out what is faster?

  • Custom User Avatar

    don't waste your time..

    I really don't want to be harsh but it may not be clear to those not in the know that this is a really really horrible solution.

    1. modifying the input, which is bad practice.
    2. while loop makes no sense.. a better terminal condition, if he is going to continue using splice and modifying the original data: while(data.length > 0). I'm going to assume that he just gave 25 so that his loop would iterate answers up to 25 bytes long.. his solution will always iterate at least 25 times, and for data with more than 25 bytes, his solution is not guaranteed to work.
    3. At this point, (for one of the test case scenarios that is only 4 bytes long) he has an array that has 21 empty arrays in it, and 4 arrays with the actual data. He is reversing ALL of these (21 of which are unnecessary), and then using array.concat to squash the empty arrays and reduce them into a single final array.
  • Custom User Avatar

    Hi! I am trying to understand this solution. Can you explain why you chose to use data.length+25 for the while loop? Why 25? Thank you!

  • Custom User Avatar

    Thank you SOOO much! I changed my check for an empty array to input.length === 0.

    I really appreciate that you gave me insight into how to figure out the problem, without just giving away what I should do. Thank you again!

  • Custom User Avatar

    Use console.log(input); as the first line of your function and you'll see the problem.
    input === [] is not the way to check if input is an empty array.

  • Custom User Avatar

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

  • Custom User Avatar

    Thank you for these comments! Your reply and solution helped me think about this problem in a completely different way.