fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5. function linesGetter() {
  6. var partial = ""
  7. return function(chunk) {
  8. var lines = (partial + chunk.toString()).split('\n')
  9. partial = lines.pop()
  10. return lines
  11. }
  12. }
  13. function flatMap(f, xs) {
  14. return xs.reduce(function(acc, x, _, _) { return acc.concat(f(x)) }, [])
  15. }
  16. function uniqFilter() {
  17. var seen = {}
  18. return function(xs) {
  19. return xs.filter(function(x, _, _) {
  20. return (x in seen) ? false : (seen[x] = true)
  21. })
  22. }
  23. }
  24. function main() {
  25. var getlines = linesGetter()
  26. var uniq = uniqFilter()
  27. process.stdin.on('data', function(chunk) {
  28. var words = flatMap(function(x) { return x.match(/\S+/g) || [] },
  29. getlines(chunk))
  30. uniq(words).forEach(function(x, _, _) { console.log(x) })
  31. })
  32. }
  33. main()
  34.  
Success #stdin #stdout 0.06s 11184KB
stdin
Standard input is empty
stdout
Standard output is empty