I'm doing a programming challenge right now but I'm struggling with getting the input right. There is no feedback on my output, only "error" which makes it really hard to debug for me. Here is the input:
4 2
1 4
2 9
4 7
5 8
and I want to collect it like this:
[4, 2, 1, 4, 2, 9, 4, 7, 5, 8];
The test environment tells me to work with the input like this:
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (line) => {
var nums = line.split(' ');
/*Solve the test case and output the answer*/
});
How ever I must be getting the wrong array for my nums variable.I tried a bunch of approaches (splitting by /n and whitespaces, iterating with for loop and push... working with rl.close...) but as there is virtually no feedback on my input I am getting kind of desperate here. A simple interface which tells me my program output would help...
SOLUTION
var nums = [];
rl.on("line", line => {
let newLine = line.split(" ");
newLine.map(line => nums.push(line));
});
rl.on("close", function() {
console.log(nums)
});
It was possible for me to debug via the terminal once I got the input right.