Created
October 24, 2021 16:43
-
-
Save aoitaku/4e652c57c064601b6695c923e0f2c06a to your computer and use it in GitHub Desktop.
被った文字のペアを消すやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>フランスゴデイナ</title> | |
<style> | |
.content { | |
width: 50em; | |
margin: 2rem auto; | |
} | |
#question { | |
font-size: 1.2em; | |
line-height: 1.5; | |
padding: 0.5em; | |
} | |
#sorted { | |
width: 41em; | |
padding: 0.5em; | |
} | |
</style> | |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
<script> | |
$(function() { | |
function hideJapaneseSentencePair (text) { | |
return text.split('').reduce((prev, a) => { | |
const index = prev.findIndex((b) => a === b); | |
if (index === -1) { | |
return [...prev, a] | |
} | |
prev[index] = '�' | |
return [...prev, '�'] | |
}, []).join(''); | |
} | |
$('#question')[0].addEventListener('blur', () => { | |
apply(hideJapaneseSentencePair($('#question').val())); | |
}); | |
function apply(text) { | |
$('#hidden').text(text); | |
} | |
apply(hideJapaneseSentencePair($('#question').val())); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="content"> | |
<textarea id="question" cols="80" rows="4"> | |
ふらんすごで「いなずま」といういみの、ほそながいしゅーくりーむのうえにちょこれーとをかけたおかしといえばなに? | |
</textarea> | |
<p id="hidden"></p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment