Ad
  • Custom User Avatar

    So clone the arrays first in your solution.

    var superSafetyArr1 = Array.prototype.concat([], arr1);
    

    Honestly, it wasn't specified, so I'd go by the YAGNI rule; simplest solution at first, refactor if necessary.

  • Custom User Avatar

    Hmm... You should update the test description as the original commenter requested then to clarify the data types. Either update the example code or the description.

  • Custom User Avatar

    That's interesting, I did not put that test case in there. I'll try to figure out who did.

  • Custom User Avatar

    The example clearly shows that all elements are integers, I think that is sufficient.

  • Custom User Avatar

    I guess you're right. Could have swore there was a weird IE situation where it didn't operate on the actual array, but I can't find anything to confirm that.

  • Custom User Avatar

    You're leaking globals (sorted1 and sorted2) here.

  • Custom User Avatar

    This actually should fail. Test it out for this case:

    arr1 = [1, 2, 2, 3]
    arr2 = [3, 3, 2, 1]
    
    arraysSimilar(arr1, arr2) === false
    

    I'll update my test cases.