Identifying non-matches in two javascript arrays

Viewed 31

I have a set of file paths in an array called directories. I have a set of files in an array called articles.

I am trying to edit the directories array by reading each file in articles and then removing the item from directories if there's a match (the files contain file paths, and I am isolating ones that are not used).

This should then produce a final directories array containing all non-matches.

At the moment the directories array reduces from 203 to 85, but some items in the array exist in the files. I am not sure what is at issue in the logic I have here:

for (let w = 0; w < articles.length; w++) {
  const data = fs.readFileSync(articles[w]);
  for (let y = 0; y < directories.length; y++) {
    const index = directories.indexOf(directories[y]);
    if (data.includes(directories[y])) {
      directories.splice(index, 1);
    }
  }
}

I know there are packages out there that do similar but they don't work for my specific use, and I have some extra functionality I want to build on top of this.

But is fs.readFile unreliable itself?

0 Answers
Related