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

havePathsInCommon will always return false for nested objects #16

Open
itsramiel opened this issue Nov 22, 2022 · 0 comments
Open

havePathsInCommon will always return false for nested objects #16

itsramiel opened this issue Nov 22, 2022 · 0 comments

Comments

@itsramiel
Copy link

the havePathInCommon function of chapter 5 uses lodash intersection which will always return false.

function havePathInCommon(diff1, diff2) {
return !_.isEmpty(_.intersection(informationPaths(diff1),
informationPaths(diff2)));
}

havePathInCommon uses informationPaths which returns an array of the paths, where each path is an array with keys as values of the array.

A return value example of informationPaths would be:

[
  ['library', 'catalog', 'authorsById', '1', 'name'] ,
  ['library', 'userManagement', 'userssById', '1', 'name'] 
]

but lodash's intersection will not deeply check this nested array, so if the above path was compared with

[
  ['library', 'catalog', 'authorsById', '1', 'name'] ,
]

It will return false because arrays are reference type.

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

1 participant