Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array of objects union has duplicates #255

Open
vabburi82 opened this issue Aug 22, 2018 · 1 comment
Open

array of objects union has duplicates #255

vabburi82 opened this issue Aug 22, 2018 · 1 comment

Comments

@vabburi82
Copy link

var old_users = [{name:'Adam'},{name:'Aron'},{name:'Bob'}];
var new_users = [{name:'Alan'},{name:'Aron'},{name:'Ben'}];

var total_users = array.union(old_users, new_users);

console.log(total_users); // [{name:'Adam'},{name:'Aron'},{name:'Bob'},{name:'Alan'},{name:'Aron'},{name:'Ben'}]

@roboshoes
Copy link
Member

This functions as intended. The comparison of duplicate values is a strict comparison. The two similar objects have the same value inside, but are not the same object.

As an example, internally it uses the unique method which by default compares with ===. Essentially the two objects {name:'Aron'} are not the same. If you type {name:'Aron'} === {name:'Aron'} into a console you will get false in return.

However, the union method should accept a comparison parameter which is a function that compares two arguments. The same way the union function does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants