I'm trying to load in two txt files and compare the differences between the two. More specifically I'm looping through one file per line and comparing it to every line in another txt file.
For the most part everything is working but I have found that I'm only able to access the array within the lr.on('line') function. However I have declared the array in the global scope.
Here is the code:
var LineByLineReader = require('line-by-line');
var lr = new LineByLineReader('phones.txt');
var lr2 = new LineByLineReader('wor.txt');
var phoneArray = [];
var worArray = [];
lr.on('error', function(err){
if(err){
console.log("We have found the following error: " + err);
}
});
lr2.on('error', function(err){
if(err){
console.log("We have found the following error: " + err);
}
});
lr.on('line', function(line){
phoneArray.push(line);
});
lr2.on('line', function(line){
worArray.push(line);
});
for(var i = 0; i < phoneArray.length; i++){
for(var x = 0; x < worArray.length; x++){
if(array1[i] === array2[x]){
console.log("Found Match: " + array2[x]);
}
}
}
LineByLineReaderwhen it's complete?