P
P
Paritet2021-09-03 01:55:10
Node.js
Paritet, 2021-09-03 01:55:10

I can’t figure out with readline, how to make it output the final result of reading lines without intermediate steps?

Help me understand, the input data is on different lines

100
200
300

the code adds a new value each time the line is read and thus displays in the console

[ '100' ]
[ '100', '200' ]
[ '100', '200', '300 ' ]

after that, all calculations are also duplicated and issued in the same format

, I don’t understand how I can force to issue an array with only total data
[ '100', '200', '300' ] , without each update

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let arr = [];
rl.on('line', line => {   

let arr1 = arr.push(line);  
let  arr2=arr.slice(0); 
console.log(arr2);

}).on('close', () => {
     process.exit(0);
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question