Блог пользователя RKCROCKS144

Автор RKCROCKS144, история, 2 года назад, По-английски

I recently started using Node JS for programming, and I had written code that take input from stdin (command prompt) in windows. The difficulty arises here is that I go on inputting values and it didn't stopped (i.e. didn't reached the end). I searched over internet and found some saying that use CTRL-D or CTRL-V, but both is not working for me. Is there anything missed up or any other method to resolve it.

Any help would be appreciated. Thanks to community.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
2 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Here is the code I had written.


process.stdin.resume(); let inputstring = ''; let currentLine = 0; process.stdin.on('data', (inputStdin) => { inputstring += inputStdin; process.stdout.write("input Called\n"); }); process.stdin.on('end', () => { inputstring = inputstring.split('\n'); let t = Number(inputstring[0]); let i = 1; process.stdout.write("End Called\n"); while (t--) { let x = Number(inputstring[i++]); solve(x); } }); function solve(n) { for (let i = n; i > 0; --i) { console.log(i); } }