Created
July 26, 2020 04:12
-
-
Save satheesh-chandran/b66c1fbfbcde772946b63da032856c35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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