<!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>