getOuterDirectory = (directories) =>
  directories.reduce((topDir, currentDir) => {
    const currentFolders = currentDir.split(path.sep);
    const topMostFolders = topDir.split(path.sep);

    if (currentFolders.length === topMostFolders.length
      && last(currentFolders) !== last(topMostFolders)) {
      return currentFolders.slice(0, -1).join(path.sep);
    }

    return currentFolders.length < topMostFolders.length
      ? currentDir
      : topDir;
  })
Given an array of directories, it returns the one that contains
all the other directories in a given array inside it.

Example:
Given an array of directories: ['/Users/Kureev/a', '/Users/Kureev/b']
the returned folder is `/Users/Kureev`

Check `getHeaderSearchPath.spec.js` for more use-cases.