fork download
  1. // Static input lines - (I did it dynamic inputs, check my repo)
  2. // github.com/reallithuanianmafia/code-care-task
  3. const inputLines = [
  4. 'asdf',
  5. 'asds',
  6. 'dfaa',
  7. 'aaaa',
  8. 'aabb',
  9. 'aaabb',
  10. ];
  11.  
  12. // Process the static input lines
  13. const output = [];
  14.  
  15. for (const line of inputLines) {
  16. const freq = {};
  17.  
  18. for (const char of line) {
  19. if (char !== ' ') {
  20. freq[char] = (freq[char] || 0) + 1;
  21. }
  22. }
  23.  
  24. const hasExactlyTwo = Object.values(freq).some(count => count === 2);
  25.  
  26. if (hasExactlyTwo) {
  27. output.push(line);
  28. }
  29. }
  30.  
  31. // Print the output
  32. console.log('Output:');
  33. console.log(output.join('\n'));
  34.  
Success #stdin #stdout 0.06s 40676KB
stdin
Standard input is empty
stdout
Output:
asds
dfaa
aabb
aaabb