Currently, I am working on a project that involves replacing letters of the alphabet with numbers resembling similar styles in typescript. For example, converting the letter 'I' to '1'. I have successfully implemented a function called replaceLettersWithNumber that accomplishes this task for all letters. However, I am facing difficulties in expanding this functionality from a simple transformation like turning 'Hello' into 'H3llo' and then further modifying it to 'H3ll0'.
The initial step involves calling a function named howManyNumberLookingCharacters to determine the count of number-like characters in the input string, which is then passed as parameters to the subsequent function. As a newcomer to StackOverflow, any suggestions or additional information you require would be highly appreciated. Although the concept seems straightforward, my current mental block is hindering progress! Thank you in advance for your assistance.
const replacementLetters = ['O', 'I', 'E', 'A', 'T'];
const replacementNumbers = ['0', '1', '3', '4', '7'];
export function howManyNumberLookingCharacters(stringToBeRead: string): {alphabeticalCharacterPosition: number[], alphabeticalCharacter: string[]} {
let alphabeticalCharacterPosition: number[] = [];
let alphabeticalCharacter: string[] = [];
for (let x = 0; x < stringToBeRead.length; x++) {
for (let i = 0; i < replacementLetters.length; i++) {
if (stringToBeRead.toLocaleUpperCase().charAt(x) == replacementLetters[i]) {
alphabeticalCharacterPosition.push(x);
alphabeticalCharacter.push(replacementLetters[i])
}
}
}
return {alphabeticalCharacterPosition, alphabeticalCharacter};
}
export function replaceLettersWithNumber(stringToBeRead: string, alphabeticalCharacterPosition: number[], alphabeticalCharacter: string[]): string[] {
let stringArray: string[] = [];
for (let x = 0; x < alphabeticalCharacter.length; x++) {
var indexInArray = replacementLetters.indexOf(alphabeticalCharacter[x].toString());
stringArray[x] = stringToBeRead.slice(0, alphabeticalCharacterPosition[x]) + replacementNumbers[indexInArray] + stringToBeRead.slice(alphabeticalCharacterPosition[x] + 1);
}
return stringArray;
}