fork download
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Check Lines</title>
  5. </head>
  6. <body>
  7. <div style="display: flex">
  8. <input type="text" id="inputText" placeholder="Enter text" /><br />
  9. <button onclick="processInput()">Check Lines</button>
  10. </div>
  11.  
  12. <pre id="output"></pre>
  13.  
  14. <script>
  15. function processInput() {
  16. const inputText = document.getElementById('inputText').value;
  17.  
  18. document.getElementById('inputText').value = '';
  19.  
  20. try {
  21. if (inputText.trim() === '') {
  22. throw new Error('Input cannot be empty');
  23. }
  24.  
  25. const text = inputText.split('\n');
  26. const output = text.filter(
  27. (line) =>
  28. hasCharacterAppearingTwice(line) &&
  29. !hasOnlyOneRepeatingCharacter(line),
  30. );
  31.  
  32. const outputElement = document.getElementById('output');
  33. output.forEach((line) => {
  34. const textNode = document.createTextNode(line);
  35. const br = document.createElement('br');
  36. outputElement.appendChild(textNode);
  37. outputElement.appendChild(br);
  38. });
  39. } catch (error) {
  40. alert('An error occurred: ' + error.message);
  41. }
  42. }
  43.  
  44. function hasCharacterAppearingTwice(line) {
  45. const charCount = {};
  46.  
  47. for (let char of line) {
  48. charCount[char] = (charCount[char] || 0) + 1;
  49. }
  50.  
  51. return Object.values(charCount).includes(2);
  52. }
  53.  
  54. function hasOnlyOneRepeatingCharacter(line) {
  55. const uniqueChars = new Set(line);
  56. return uniqueChars.size === 1;
  57. }
  58. </script>
  59. </body>
  60. </html>
  61.  
Success #stdin #stdout 0.02s 25796KB
stdin
Standard input is empty
stdout
<!DOCTYPE html>
<html>
  <head>
    <title>Check Lines</title>
  </head>
  <body>
    <div style="display: flex">
      <input type="text" id="inputText" placeholder="Enter text" /><br />
      <button onclick="processInput()">Check Lines</button>
    </div>

    <pre id="output"></pre>

    <script>
      function processInput() {
        const inputText = document.getElementById('inputText').value;

        document.getElementById('inputText').value = '';

        try {
          if (inputText.trim() === '') {
            throw new Error('Input cannot be empty');
          }

          const text = inputText.split('\n');
          const output = text.filter(
            (line) =>
              hasCharacterAppearingTwice(line) &&
              !hasOnlyOneRepeatingCharacter(line),
          );

          const outputElement = document.getElementById('output');
          output.forEach((line) => {
            const textNode = document.createTextNode(line);
            const br = document.createElement('br');
            outputElement.appendChild(textNode);
            outputElement.appendChild(br);
          });
        } catch (error) {
          alert('An error occurred: ' + error.message);
        }
      }

      function hasCharacterAppearingTwice(line) {
        const charCount = {};

        for (let char of line) {
          charCount[char] = (charCount[char] || 0) + 1;
        }

        return Object.values(charCount).includes(2);
      }

      function hasOnlyOneRepeatingCharacter(line) {
        const uniqueChars = new Set(line);
        return uniqueChars.size === 1;
      }
    </script>
  </body>
</html>