I have some tasks, basically a CLI script that takes x lines, and based on said lines makes some calculations.
Eg.:
Input:
3 // number of iterations to do something
ATCCGCTTAGAGGGATT // first string
GTCCGTTTAGAAGGTTT // second string
// 2nd iteration starts
abcdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyza
// 3rd iteration starts
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
Output:
ATCCGCTTAGAGGGATT // first string
GTCCGTTTAGAAGGTTT // second string
*....*.....*..*.. // visual marker of differences between the two strings(*)
abcdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyza
**************************
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
....................................
What i've tried:
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
prompt: ''
})
let numberOfTests = 0;
let firstText = '';
let secondText = '';
let differences = '';
rl.prompt();
rl.on('line', (line: any) => {
let loop = 0;
numberOfTests = line;
firstText = line;
secondText = line;
calculateDifferences(firstText, secondText); // basic function that loops through the arrays and makes the visual marker.
loop ++;
if (loop === numberOfTests) {
rl.close();
}
}).on('close', () => {
console.log('Have a great day!');
process.exit(0);
});
The main issue I am facing is that i cannot separate the input stream from one another. By the time we are at the secondText every variable will be equal to wheter I input on the 3rd time.
How can you separate the inputs from each other?
Node documentation is not so detailed about this.Or I cannot see it through correctly.