Read From Stdin Lines
NodeJS
Easy
6 views
Problem Description
Read all stdin, split into lines, and print count.
Input Format
stdin: any text.
Output Format
Print integer.
Constraints
Trim ending newline correctly.
Official Solution
const fs = require('fs');
const text = fs.readFileSync(0, 'utf8');
if (!text) process.exit(0);
const lines = text.replace(/\
/g, '').split('\
');
if (lines.length && lines[lines.length - 1] === '') lines.pop();
console.log(lines.length);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!