Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env node
- 'use-strict'
- const process = require('process');
- const fs = require('fs');
- try {
- let string = 0;
- let word = 0;
- let symbol = 0;
- let now = 0;
- if (process.argv.length === 2) {
- const stdin = process.openStdin();
- const func = (x) => {
- now = 0;
- const str = x.toString('utf-8');
- string++;
- symbol += str.length;
- for (let i = 0; i < str.length; i++) {
- if (str[i] === ' ') {
- if (i !== 0) {
- if (i === str.length - 1 && str[i - 1] !== ' ') now++;
- if (i !== str.length - 1 && str[i - 1] !== ' ' && str[i + 1] !== ' ') now++;
- }
- }
- }
- word += now;
- };
- stdin.addListener('data', func);
- }
- if (process.argv.length === 2) console.log(string + ' ' + word + ' ' + symbol);
- } catch (e) {
- console.error(e.message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement