fork download
  1. // your code goes here
  2.  
  3. function findLinesWithTwoSymbol(input) {
  4. // Split the input into lines you can write another symbol for split
  5. const lines = input.split('\n');
  6.  
  7. // Iterate through each line
  8. lines.forEach(line => {
  9. const charCount = [];
  10.  
  11. // Iterate through each character in the line
  12. for (let char of line) {
  13. // Get the character code as the index (unique for each character)
  14. const index = char.charCodeAt(0);
  15.  
  16. // Increment the count at the corresponding index
  17. charCount[index] = (charCount[index] || 0) + 1;
  18. }
  19.  
  20. // Check if any character appears exactly twice
  21. if (charCount.some(count => count === 2)) {
  22. console.log(line);
  23. }
  24. });
  25. }
  26.  
  27. // Example usage:
  28. const input = `asdf
  29. fdas
  30. asds
  31. d
  32. fm
  33. dfaa
  34. aaaa
  35. aabb
  36. aaabb`;
  37.  
  38. findLinesWithTwoSymbol(input);
Success #stdin #stdout 0.03s 17252KB
stdin
Standard input is empty
stdout
asds 
dfaa 
aabb 
aaabb