DEV Community

Discussion on: How to Compare Arrays in JavaScript Efficiently

 
simonas88 profile image
simonas88

No extra memory implies that the argument variable is mutated in sorting step. I wonder if that is okay.

Thread Thread
 
costinmanda profile image
Costin Manda

Sure. Depends on the requirements. You could add 2n for copying the arrays, I suppose. I am not even saying that's it's the best way, but I think it's better than the one in the post.

Thread Thread
 
simonas88 profile image
simonas88

Nevermind the intricacies of memory complexity, I think the point of the post was to demonstrate the technique of frequency counting which might be the way to go in some similar problem.

Thread Thread
 
costinmanda profile image
Costin Manda

The post is called "How to Compare Arrays in JavaScript Efficiently". And I agree that count sort is a particular algorithm that might be useful in this case, but not frequency counting, which is just needlessly counting duplicates when that was not the requirement of the task.

I also think in any content that claims "A smarter way" one should consider all concerns, including memory consumption.