fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5. var readline = require("readline");
  6.  
  7. function uniqWord(callback) {
  8. var seen = {};
  9. return function (line) {
  10. var words = line.match(/\S+/g) || [];
  11. words.forEach(function(word) {
  12. if (word in seen) return;
  13. seen[word] = true;
  14. callback(word);
  15. });
  16. }
  17. }
  18.  
  19. function main() {
  20. var rl = readline.createInterface(process.stdin, process.stdout);
  21.  
  22. rl.on('line', uniqWord(function(word) {
  23. console.log(word);
  24. }));
  25. }
  26. main()
Success #stdin #stdout 0.07s 10968KB
stdin
aaa bbb ccc bbb aaa
ddd ccc eee aaa fff
fff ccc aaa ggg eee
stdout
aaa
bbb
ccc
ddd
eee
fff