loading...

re: Handling Array Duplicates Can Be Tricky VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I'm no expert, but you will loose some item in your array (every non serializable like functions), it will fail on non utf8 encoded string, throws ...
 

Agreed, it's not great in most cases. However, sometimes it is just practical from a dev productivity point of view:

  • writing your own datastructure-comparison will introduce more error sources, especially if you need to refactor. So writing your own is only economical on frequently used code
  • order: using service workers or persisting to localStorage means your data structure will "exit" the JavaScript VM's context. Then you definitely shouldn't use it. If you always generate it the same way in the same runtime context, you're safe(r)
  • it can have better performance than other comparison algorithms, especially on smaller datasets
  • Sometimes you don't want to have functions in your objects, by design. E.g. when using redux. Here it's also safe(r)

If you use it, wrap it in your own compareXYZ() util-function, so you can
a) adjust it later
b) see that function in your profiler pop up

code of conduct - report abuse