fork download
  1. const readline = require('readline');
  2.  
  3. const rl = readline.createInterface({
  4. input: process.stdin,
  5. output: process.stdout
  6. });
  7.  
  8. const checkIfLineContainsTwoTimesChars = line => {
  9. const arr = line.split('');
  10. const hash = new Map();
  11. let result = false;
  12.  
  13. for (let i = 0; i < arr.length; i++) {
  14. if (hash.get(arr[i]) === undefined) {
  15. hash.set(arr[i], 1);
  16. } else {
  17. const value = hash.get(arr[i]);
  18. if (value) {
  19. hash.set(arr[i], value + 1);
  20. }
  21. }
  22. }
  23.  
  24. hash.forEach((v, k) => {
  25. if (v==2) result = true;
  26. });
  27.  
  28. return result;
  29. };
  30.  
  31. rl.on('line', (input) => {
  32. if (checkIfLineContainsTwoTimesChars(input)) {
  33. rl.output.write(input +'\n');
  34. }
  35. });
  36.  
Success #stdin #stdout 0.07s 30316KB
stdin
asdf
fdas
asds
d fm
dfaa
aaaa
stdout
asds
dfaa