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

Remove duplicates of Arrays of Objects #10

Closed
wants to merge 7 commits into from

Conversation

jusimen
Copy link

@jusimen jusimen commented Aug 20, 2024

This PR introduces a code change to handle cases where a property of the obj object contains an array of objects. The enhancement ensures that duplicate objects within these arrays are filtered out, maintaining only unique entries.

The original implementation effectively removed duplicates in arrays of primitive values but didn't address arrays containing objects. This oversight could lead to scenarios where duplicate objects remain in properties that should only contain unique entries. The new logic ensures that such duplicates are removed, preserving the integrity of the obj properties.

Example

Input

[{
  "name": "Jusi",
  "numbers": [ 1, 1, 2, 3 ],
  "devices": [
    { "software": "iOS", "name": "iPhone 12'"},
    { "software": "Android", "name": "Pixel 5"}
  ]
},

{
  "name": "Monteiro",
  "numbers": [ 2, 3, 4 ],
  "devices": [
    { "software": "iOS", "name": "iPhone 12" },
    { "software": "Windows", "name": "Surface Pro" }
  ]
}]

Output

{
  "name": "Monteiro",
  "numbers": [ 1, 2, 3, 4 ],
  "devices": [
    { "software": "iOS", "name": "iPhone 12" },
    { "software": "Android", "name": "Pixel 5" },
    { "software": "Windows", "name": "Surface Pro" }
  ]
}

Note

This package is awesome, very well build, thank you @jhildenbiddle

@jusimen jusimen closed this Aug 21, 2024
@jusimen jusimen deleted the dedup-array-of-objects branch August 21, 2024 11:02
@jusimen jusimen restored the dedup-array-of-objects branch September 19, 2024 18:25
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

Successfully merging this pull request may close these issues.

1 participant