Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Almacenar todas las combinaciones posibles de una cadena cuando solo caracteres específicos

Estoy tratando de sustituir letras del alfabeto con números que se ven similares en estilo en mecanografiado. Es decir, la letra I a 1. Tengo una función de trabajo llamada replaceLettersWithNumber que completa esto con todas las letras, sin embargo, estoy luchando por comprender y lograr una solución de trabajo donde se extienda desde solo, Hola -> H3llo -> Hell0, para finalmente, H3ll0.

Primero se llama a la función llamada howManyNumberLookingCharacters, y las matrices devueltas son parámetros en la función inferior. Soy nuevo en StackOverflow, así que avíseme si hay más información que pueda proporcionar. Siento que esto es bastante sencillo, ¡sin embargo, mi cerebro no está cooperando! Gracias.

 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; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La forma más fácil de generar combinaciones es usar la recursividad.

En cada nivel donde hay un reemplazo disponible, llama a la función con ambas versiones, así:

 const replacementNumbers = { 'O': '0', 'I': '1', 'E': '3', 'A': '4', 'T': '7', }; function replacementCombinations(input: string): string[] { const uppercase = input.toUpperCase() const combinations: string[] = [] function r(str: string): void{ if(str.length >= input.length){ combinations.push(str) return } r(str + input[str.length]) if(uppercase[str.length] in replacementNumbers) r(str + replacementNumbers[uppercase[str.length]]) } r('') return combinations }

Tenga en cuenta que este código asume que está haciendo reemplazos de un solo carácter.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!