|
1 | 1 | //EJERCICIO |
2 | 2 | //Acceso a caracteres específicos |
3 | | -//Subcadenas |
| 3 | +const myAlphabet: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 4 | + |
| 5 | +console.log(myAlphabet[17] + myAlphabet[8] + myAlphabet[2]) |
| 6 | + |
| 7 | +const nameChart1: string = myAlphabet.charAt(17) |
| 8 | +const nameChart2: string = myAlphabet.charAt(8) |
| 9 | +const nameChart3: string = myAlphabet.charAt(2) |
| 10 | + |
| 11 | +console.log(nameChart1, nameChart2, nameChart3) |
| 12 | + |
| 13 | +const rPosition: number = myAlphabet.indexOf('R') |
| 14 | + |
| 15 | +console.log(`La letra R es la número ${rPosition + 1} de nuestro alfabeto`) |
| 16 | + |
4 | 17 | //Longitud |
5 | | -//Concatenación |
6 | | -let myString1: string = 'Hola, ' |
7 | | -let myString2: string = 'TypeScript' |
| 18 | +const phrase: string = 'Me encantan las papas fritas' |
| 19 | + |
| 20 | +console.log(`\"${phrase}\" tiene ${phrase.length} caracteres`) |
| 21 | + |
| 22 | +//Subcadenas |
| 23 | +const phraseSlice: string = phrase.slice(16) |
| 24 | + |
| 25 | +console.log(phraseSlice) |
| 26 | + |
| 27 | +const heroes: string = 'Batman le gana a Superman' |
| 28 | +const Batman: string = heroes.substring(0, 6) |
| 29 | +const Superman: string = heroes.substring(17) |
| 30 | + |
| 31 | +console.log(Batman) |
| 32 | +console.log(Superman) |
8 | 33 |
|
9 | | -let message: string = myString1.concat(myString2) |
| 34 | +//Concatenación |
| 35 | +let action: string = ' está peleando con ' |
10 | 36 |
|
11 | | -console.log(message) |
| 37 | +console.log(Batman.concat(action, Superman)) |
| 38 | +console.log(Batman + action + Superman) |
12 | 39 |
|
13 | 40 | //Repetición |
| 41 | +let ric: string = 'Ric ' |
| 42 | + |
| 43 | +console.log(ric.repeat(3)) |
| 44 | + |
14 | 45 | //Recorrido |
| 46 | +for (let i = 0; i < myAlphabet.length; i++) { |
| 47 | + console.log(myAlphabet[i]) |
| 48 | +} |
| 49 | + |
15 | 50 | //Conversión a mayúsculas y minúsculas |
| 51 | +const fruits: string[] = ['fresa', 'PARCHITA', 'LiMÓn', 'Mango'] |
| 52 | + |
| 53 | +fruits.forEach((fruit) => { |
| 54 | + console.log(fruit.toUpperCase()) |
| 55 | +}) |
| 56 | + |
| 57 | +fruits.forEach((fruit) => { |
| 58 | + console.log(fruit.toLowerCase()) |
| 59 | +}) |
| 60 | + |
16 | 61 | //Reemplazo |
| 62 | +let musicPlayer = 'Music Player current song: The Pretender - Foo Fighters' |
| 63 | + |
| 64 | +console.log(musicPlayer) |
| 65 | +console.log(musicPlayer.replace('The Pretender - Foo Fighters', 'Monster - Skillet')) |
| 66 | + |
17 | 67 | //División |
| 68 | + |
18 | 69 | //Unión |
| 70 | + |
19 | 71 | //Interpolación |
| 72 | +console.log(`\n\"TypeScript es JavaScript premium\" \n\n\t\t\t${ric.toUpperCase()}`) |
| 73 | + |
20 | 74 | //Verificación |
| 75 | + |
21 | 76 | //Otros |
22 | 77 |
|
23 | 78 | //EXTRA |
@@ -63,5 +118,5 @@ function analyzeTheseWords(word1: string, word2: string) { |
63 | 118 | isogram(word2) |
64 | 119 | } |
65 | 120 |
|
66 | | -analyzeTheseWords('Roma', 'Amor') |
67 | | -analyzeTheseWords('Radar', 'Paloma') |
| 121 | +// analyzeTheseWords('Roma', 'Amor') |
| 122 | +// analyzeTheseWords('Radar', 'Paloma') |
0 commit comments