Im trying to dig into this kattis.com challenge called counting stars using NodeJs. If you see the input example, it always start with a line of two integers, the first one represents the number of rows, the second one represents the numbers of columns per row, there are a lot of examples with C and Java, but I want to solve this with JS (Nodejs). How I can read from the terminal and iterate line by line, I tried with the next code
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var lines = [];
rl.on('line', line => {
lines.push(line);
console.log(lines);
});
But for some reason, if I input this sample
3 10
#-########
----------
#-########
It only show me the first 3 lines, also tried with this line while (line = readline()) {}
, but also not working because of readline isn't a function
In Java they use a class of Scanner(System.in);
, and probably that class make things easier