Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 3
    This only does work for certain arrays, and will be very slow with big arrays. Commented Mar 21, 2013 at 21:01
  • 2
    Generating JSON is looping too, you just (or it seems so) don't know about it. Besides looping, generating JSON also requires more memory - it creates 2 string representations of said arrays before comparing. The downwote function is implemented to order answers from the best to the worst. I think your answer is not a good answer, so I downvoted it. Commented Mar 21, 2013 at 22:08
  • 2
    Sorry, I just said JSON instead of .join(). Maybe if you stated your second solution as primary (as it is the better one, though toothless against multidimensional arrays), I would not judge you that way. So far, I downoted all answers that do convert arrays to strings. As well, I upvoted all that use the right way, in case you needed that to know. This means @Tim Down's answer and Bireys one. Commented Mar 21, 2013 at 23:01
  • 6
    First version FAILS: checkArrays([1,2,3] , ["1,2",3]) == true, and it's very unlikely that that's what you want to happen! Commented Oct 16, 2014 at 3:46
  • 2
    @epascarello: Yes, you can but (aside from the inefficiency of the very long separator you suggest) it means there will be edge cases (where the array happens to contain a string with your separator in it) where the checkArrays() function misbehaves. This might not be a problem if you know something about the contents of the arrays (so you can choose a separator you're sure won't be in the array items), but if you're trying to write a general array-comparison function, then using join() like this makes it subtly buggy! Commented Oct 17, 2014 at 13:49