jashkenas / jashkenas/underscore

_.union doesn't work with arrays of objects

Open
#2,311 32 comments 0 reactions 0 assignees View on GitHub
breaking change
Dominant language
JavaScript
Stars
27.3k
Forks
5.4k
Avg merge
2d 5h
Merged PRs (30d)
1

Description

_.union will always produce duplicates when passed arrays of objects.

e.g. `_.union( [ { a:1 } ], [ { a:1 } ])` will return `[ { a:1 }, { a:1 } ]`

Perversely, underscore's own isEqual function will tell you that the objects in question are equal. Maybe we could have a flag/option which dictates the equality comparison to use, or the option to pass in a comparator?

Contributor guide

Open the contributing guide

Research direction

Reproduce the example with _.union and compare its behavior with _.isEqual; no source file or test is named in the issue. Before changing anything, resolve whether object equality or a caller-supplied comparator is intended, then add regression coverage for the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.