Advertisement
Void-voiD

Untitled

Dec 20th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #! /usr/bin/env node
  2. 'use-strict'
  3.  
  4. const process = require('process');
  5. const fs = require('fs');
  6.  
  7. try {
  8. let string = 0;
  9. let word = 0;
  10. let symbol = 0;
  11. let now = 0;
  12. if (process.argv.length === 2) {
  13. const stdin = process.openStdin();
  14. const func = (x) => {
  15. now = 0;
  16. const str = x.toString('utf-8');
  17. string++;
  18. symbol += str.length;
  19. for (let i = 0; i < str.length; i++) {
  20. if (str[i] === ' ') {
  21. if (i !== 0) {
  22. if (i === str.length - 1 && str[i - 1] !== ' ') now++;
  23. if (i !== str.length - 1 && str[i - 1] !== ' ' && str[i + 1] !== ' ') now++;
  24. }
  25. }
  26. }
  27. word += now;
  28. };
  29. stdin.addListener('data', func);
  30. }
  31. if (process.argv.length === 2) console.log(string + ' ' + word + ' ' + symbol);
  32. } catch (e) {
  33. console.error(e.message);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement