More than a decadeΒ΄ of experience as a software developer. Software architecture, team coaching, working with all technologies and on all platforms used for web-facing products.
Your Unique Array of Objects solution uses the incredibly expensive JSON.stringify and JSON.parse to do object comparison. While the code looks neat it is probably the least efficient way to go about it.
A better approach would use _.isEqual for deep comparisons, or a concrete comparison on the significant fields, if not all fields are significant (which they rarely are --- e.g. an id field may imply the state of the other fields).
As others have pointed out, your solution is not even correct.
I found this post via the "Top" posts page, which seems to be because it is getting a lot of engangement. I can't help but wonder whether your bad advice is intentional---to get engangement. You've gotten lots of feedback, but made no adjustments to the post.
The only thing these tips will kill is your app performance.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
π© Red flag! I wouldn't trust the above code for general use.
Your Unique Array of Objects solution uses the incredibly expensive
JSON.stringifyandJSON.parseto do object comparison. While the code looks neat it is probably the least efficient way to go about it.A better approach would use _.isEqual for deep comparisons, or a concrete comparison on the significant fields, if not all fields are significant (which they rarely are --- e.g. an
idfield may imply the state of the other fields).As others have pointed out, your solution is not even correct.
I found this post via the "Top" posts page, which seems to be because it is getting a lot of engangement. I can't help but wonder whether your bad advice is intentional---to get engangement. You've gotten lots of feedback, but made no adjustments to the post.
The only thing these tips will kill is your app performance.