JSFiddle - React, Tailwind, and code Playground
by XTREME104
HTML
<p>
Can correct:
<br/>
1 misspeled letter in each word.
<br/>
or
<br/>
An extra letter at the beginning of a word.
<br/>
or
<br/>
An extra letter at the end of a word.
<br/>
Words are seperated by anything except letters and numbers.
<br/>
</p>
<br/><br/>
<textarea id="input" onkeyup="onCorrect()"></textarea>
<p id="output"></p>
<script>
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var numbers = "0123456789";
var dictionary = [
"a", "ab", "abandon", "abandoned", "abbreviate", "abreviation", "abdomen", "abide", "ability", "abject", "ablaze", "able", "abloom", "abnormal", "aboard", "abode", "abolish", "abominable", "abominate", "abomination", "abort", "abortion", "abortionist", "abound", "about", "are", "really", "was", "here", "why", "how", "where", "when", "are", "what", "who", "hi", "hello", "bye", "goodbye", "up", "down", "left", "right", "forward", "backward", "front", "back", "side", "top", "bottom", "you", "we", "us", "done", "do", "think", "your", "yours", "our", "ours", "their", "theirs"
];
var replaceBefores = [[" ", "\t"]];
var replaceAfters = [["im", "I'm"]];
function correct (input) {
var result = [];
var words = [];
var word = "";
for (var i = 0; i < replaceBefores.length; i++) {
input = input.replace(replaceBefores[i][0], replaceBefores[i][1]);
}
for (var i = 0; i < input.length; i++) {
if (alphabet.indexOf(input.charAt(i).toLowerCase()) == -1 && numbers.indexOf(input.charAt(i).toLowerCase()) == -1) {
if (word && word != "") {
words.push([correctWord(word), true]);
}
words.push([input.charAt(i),...