10000 `uniqBy` returns incorrect values · Issue #5951 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

uniqBy returns incorrect values #5951

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

Open
vinaysharma14 opened this issue Dec 18, 2024 · 3 comments
Open

uniqBy returns incorrect values #5951

vinaysharma14 opened this issue Dec 18, 2024 · 3 comments

Comments

@vinaysharma14
Copy link
import _ from 'lodash';

const result = _.uniqBy(
    [
        { name: 'Foo' },
        { name: 'Foo' },
        { name: 'Bar' },
        { name: 'Bar' },
        { person: { name: 'Foo' } },
        { person: { name: 'Foo' } },
        { person: { name: 'Bar' } },
        { person: { name: 'Bar' } },
    ],
    'person.name',
);

// result
[
  { name: 'Foo' }, // it shouldn't be present
  { person: { name: 'Foo' } },
  { person: { name: 'Bar' } }
]
@hamza-elmoudden
Copy link

If you want to use _.uniqBy to ensure that duplicates are removed based on the person.name property only, you can add a condition to check if the object has a person property before manipulating the data.

import _ from "lodash"

const result = _.uniqBy(
[
{ name: 'Foo' },
{ name: 'Foo' },
{ name: 'Bar' },
{ name: 'Bar' },
{ person: { name: 'Foo' } },
{ person: { name: 'Foo' } },
{ person: { name: 'Bar' } },
{ person: { name: 'Bar' } },
].filter(item => item.person?.name),
(item) => item.person?.name
);

console.log(result);

@Rangarajanl-OpenSource
Copy link

@vinaysharma14 I personally see this as a potential core feature that could be extremely useful. If you agree, please consider reviewing and upvoting the issue: #5953.
I’ve made sure to update the ticket diligently with all relevant details. Feel free to add any further insights you think are necessary. If you're open to it, we could also collaborate on implementing this change together!

vedant713 added a commit to vedant713/lodash that referenced this issue Mar 5, 2025
Adds a new uniqByExisting function that behaves like uniqBy but skips elements
where the specified property path doesn't exist. This addresses issue lodash#5951
and partially implements the feature request in lodash#5953 for mixed data formats.
@FMaxey3
Copy link
FMaxey3 commented Apr 8, 2025

@eugenemaxey curl -o media3-migration.sh
#"https://raw.githubusercontent.com/google/ExoPlayer/r2.19.1/media/3-migration.sh"

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

No branches or pull requests

4 participants
0