Skip to content

Instantly share code, notes, and snippets.

@satheesh-chandran
Created July 26, 2020 04:12
Show Gist options
  • Save satheesh-chandran/b66c1fbfbcde772946b63da032856c35 to your computer and use it in GitHub Desktop.
Save satheesh-chandran/b66c1fbfbcde772946b63da032856c35 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const makeObject = function(string,suffix){
suffix[string.slice(-4)] = string;
return suffix;
};
const matchContents = function(firstTexts,secondTexts){
const suffix = {}
const matchedArray = [];
/*const makeObject = function(string){
suffix[string.slice(-4)] = string;
};*/
for(let line of firstTexts){
makeObject(line,suffix)
}
for(let line of secondTexts){
let matchingString = suffix[line.slice(0,4)];
if(matchingString.slice(-4) == line.slice(0,4)){
matchedArray.push(matchingString.slice(0,-4) + line)
}
}
return matchedArray;
};
const main = function(){
const firstTexts = fs.readFileSync('./match_data/match_large_1.txt','utf8').split('\n');
const secondTexts = fs.readFileSync('./match_data/match_large_2.txt','utf8').split('\n');
console.log(matchContents(firstTexts,secondTexts));
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment