Ad
  • Default User Avatar
  • Default User Avatar

    Maybe I should add an extra test for that :)

  • Custom User Avatar

    Seems it has something to do with the delete that[j]; line. If I comment it out, the length change works fine. I'm not entirely sure why you're deleting those items, anyway; if the length changes to omit those items, then they'll be deleted. And if the length doesn't change to omit those items, there are effectively undefineds in place of those items, which isn't a desired effect of splice anyway, right?

  • Custom User Avatar

    Yeah-- But you can post spoilers. So you can post your full code, mark is as a spoiler (thereby hiding it from yourself), but we can still see it, and you can still see our replies to it. I'll have a look a tthe gist anyway...

  • Default User Avatar

    Very curious. Your code looks like it should work. It's hanging on this line in reindex():

    that.length = newLength
    

    It doesn't time out if you put a return right before that line, and it does time out if you put a return right after that line. Just before that line, the contents of that is [1,4,undefined,undefined], that.length is 4, and newLength is 2.

    So I don't see a reason that line should fail. It could be that the particular implementation of JavaScript that Codewars is using has a bug which only happens when both the delete statement and array .length truncation are used. It works fine for me in the browser (Chrome).

  • Custom User Avatar

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