fork(1) download
  1. /**
  2.  * Counts the occurrences of each character in a given string
  3.  * @param {string} line - The input string to count characters from
  4.  * @returns {object} - An object containing the counts of each character
  5.  */
  6. function getCharCounts(line = '') {
  7. return line
  8. .split('')
  9. .reduce((acc, char) => ({ ...acc, [char]: (acc[char] || 0) + 1 }), {});
  10. }
  11.  
  12. // Read input line by line using the readline function
  13. // Check if any character in each line appears exactly twice, and print the line if so
  14. while ((line = readline())) {
  15. if (Object.values(getCharCounts(line)).some((count) => count === 2)) {
  16. print(line);
  17. }
  18. }
  19.  
Success #stdin #stdout 0.03s 19756KB
stdin
asdf
fdas
asds
d fm
dfaa
aaaa
aabb
aaabb
stdout
asds
dfaa
aabb
aaabb