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

diff of equal objects should return empty array #63

Closed
royaldark opened this issue Mar 11, 2016 · 2 comments
Closed

diff of equal objects should return empty array #63

royaldark opened this issue Mar 11, 2016 · 2 comments
Assignees

Comments

@royaldark
Copy link

Why does diff({}, {a: 4}) return an array of differences, but diff({}, {}) return undefined? I would expect it to return [] instead.

This makes iteration over the changes much easier. No check for undefined is needed.

We also occasionally use diff only to count the number of differences. This means code like diff(a, b).length will break on equal objects.

@flitbit
Copy link
Collaborator

flitbit commented May 8, 2016

The reason diff({}, {}) returns undefined is because my own prevailing pattern was if(diff(a,b)).

Your diff(a,b).length pattern also makes sense. I'd happily take a PR supporting both patterns. Such could be accomplished by exporting a slightly different accumulateDiff implementation; I'd probably call it listDiff but that's just me.

@webOS101
Copy link

I must say I just got bit by this. My build scripts never hit a build that didn't have differences until today and then 💥 . Can you at least update the README to call out this completely unexpected behavior?

@cerebralkungfu cerebralkungfu self-assigned this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants