fork download
  1. function hasCharacterAppearingExactlyTwice(line) {
  2. const charCount = {};
  3.  
  4. for (let char of line) {
  5. charCount[char] = (charCount[char] || 0) + 1;
  6. }
  7.  
  8. return Object.values(charCount).includes(2);
  9. }
  10.  
  11. try {
  12. while (true) {
  13. const line = readline();
  14.  
  15. if (line === null || line === undefined || line === '') {
  16. break;
  17. }
  18.  
  19. if (hasCharacterAppearingExactlyTwice(line)) {
  20. console.log(line);
  21. }
  22. }
  23. } catch (e) {
  24. console.error("Error: Could not read input. Ensure the environment supports readline().");
  25. }
Success #stdin #stdout 0.04s 16804KB
stdin
qwqwqw
adsdfasd
ppopo
klklkl
stdout
adsdfasd
ppopo