Skip to content

havePathsInCommon will always return false for nested objects #16

@itsramiel

Description

@itsramiel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions