Last active
November 15, 2021 15:42
-
-
Save lethak/f7768acc44d0d6fbf462136a2fbe5946 to your computer and use it in GitHub Desktop.
Custom Homonyms Generator
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
let getHomonymes = function (pseudo = '') { | |
const homonymes = [] | |
const map = { | |
'o': ['O', '0'], | |
'O': ['0', 'o'], | |
'0': ['o', 'O'], | |
'i': ['L', 'l', 'I', '1'], | |
'I': ['L', 'l', 'i', '1'], | |
'1': ['L', 'l', 'i', 'I'], | |
'l': ['L', '1', 'i', 'I'], | |
'L': ['l', 'I', '1', 'i'], | |
'a': ['A', '4'], | |
'A': ['a', '4'], | |
'e': ['E', '3'], | |
'E': ['e', '3'], | |
'3': ['e', 'E'], | |
'4': ['a', 'A'], | |
} | |
for (iLetter in pseudo) { | |
iLetter = parseInt(iLetter) | |
const letter = pseudo[iLetter] | |
if (map.hasOwnProperty(letter)) { | |
const pseudoPart1 = pseudo.substr(0, iLetter) | |
const pseudoPart2 = pseudo.substr(1 + iLetter) | |
for (mapLetterCandidate of map[letter]) { | |
const newPseudo = '' + pseudoPart1 + mapLetterCandidate + pseudoPart2 | |
if(!homonymes.includes(newPseudo)) { | |
homonymes.push(newPseudo) | |
} | |
} | |
} | |
} | |
return homonymes | |
} | |
let getGlobalHomonymes = function (pseudo = '') { | |
const finalHomonymes = [pseudo] | |
const doneHomos = [] | |
let finalHomonymesPreCount = 0 + finalHomonymes.length | |
let iWhile = 0 | |
if (pseudo.length !== 0) { | |
while (iWhile === 0 || finalHomonymes.length > finalHomonymesPreCount) { | |
finalHomonymesPreCount = 0 + finalHomonymes.length | |
for (iFinalHomonyme in finalHomonymes) { | |
const finalHomonyme = finalHomonymes[iFinalHomonyme] | |
if (!doneHomos.includes(finalHomonyme)) { | |
doneHomos.push(finalHomonyme) | |
const homos = getHomonymes(finalHomonyme) | |
for (iHomo in homos) { | |
const homo = homos[iHomo] | |
if(!finalHomonymes.includes(homo)) { | |
finalHomonymes.push(homo) | |
} | |
} | |
} | |
} | |
iWhile++ | |
} | |
} | |
return finalHomonymes | |
} | |
let writeLines = function (lines = []) { | |
document.open() | |
document.write(`<h3>count = ${lines.length}</h3><hr/>`) | |
for (iLine in lines) { | |
const line = lines[iLine] | |
document.write(line + '<br/>') | |
} | |
document.close() | |
} | |
writeLines(getGlobalHomonymes('LethaK')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment