Ad
  • Custom User Avatar

    Deep clone is simple: what if some elements in your array are objects? Obviously you should copy them too, or else if you make changes to this objects, it'll be reflected on the one in the other array too.

    And what if some elements of that object is, again, objects? The rabbit hole is deep here, and you need deep clone to clone all of them ;-)

  • Custom User Avatar

    No, that's still the same object. Look for built-in array methods to get a copy of an array ;-)

  • Custom User Avatar

    You made changes to the input array. Because it's an object the changes will persist even outside your function ;-)

    The simplest fix at your end is to copy the array (deep copy, but for this kata just a shallow copy is enough). It's both discouraged for writing code that mutates the input, and writing code that'll break if input is mutated ;-)

  • Custom User Avatar

    Looks like mutating the input is causing problems again.

    I'll resolve this issue since it's not clear about the actual issue, and re-raise a clear one. Meanwhile, don't mutate the input ;-)