forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Retos/Reto #1 - EL LENGUAJE HACKER [Fácil]/typescript/JvegaG.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Escribe un programa que reciba un texto y transforme lenguaje natural a | ||
* "lenguaje hacker" (conocido realmente como "leet" o "1337"). Este lenguaje | ||
* se caracteriza por sustituir caracteres alfanuméricos. | ||
* - Utiliza esta tabla (https://www.gamehouse.com/blog/leet-speak-cheat-sheet/) | ||
* con el alfabeto y los números en "leet". | ||
* (Usa la primera opción de cada transformación. Por ejemplo "4" para la "a") | ||
*/ | ||
|
||
// Solucion 01: Facil | ||
const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', | ||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', | ||
'V', 'W', 'X', 'Y', 'Z' | ||
]; | ||
|
||
const leetArray = ['4', 'I3', '[', ')', '3', '|=', '&', '#', '1', ',_|', | ||
'>|', '1', '/\\/\\', '^/', '0', '|*', '(_,)', 'I2', '5', '7', '(_)', | ||
'\\/', '\\/\\/', '><', 'j', '2' | ||
]; | ||
|
||
const changeToLeet = (text: string): string => { | ||
let textToLeet = ''; | ||
|
||
text.split('').forEach(item => { | ||
const character = item.toUpperCase(); | ||
const letterPosition = letters.indexOf(character); | ||
|
||
textToLeet += (letterPosition !== -1) ? leetArray[letterPosition] : character; | ||
}) | ||
|
||
return textToLeet; | ||
} | ||
|
||
const textForTest = "Que Dios me ayude con este codigo :)"; | ||
const newText = changeToLeet(textForTest); | ||
console.log(newText) | ||
|
||
|
||
|
||
// Solucion 02: compleja (usando Map) | ||
const leetMap = new Map<string, string>() | ||
letters.forEach((item, index) => leetMap.set(item, leetArray[index])); | ||
|
||
const newChangeToLeet = (text: string): string => { | ||
let textToLeet = ''; | ||
text.split('').forEach(item => textToLeet += leetMap.get(item.toUpperCase()) ?? item ) | ||
|
||
return textToLeet | ||
} | ||
|
||
const secondNewText = newChangeToLeet(textForTest); | ||
console.log(secondNewText) |