Skip to content

Commit 9b6276e

Browse files
authored
Merge pull request mouredev#7463 from ssanjua/js_05
#5 - JavaScript
2 parents de8fbf1 + db76e38 commit 9b6276e

File tree

1 file changed

+50
-0
lines changed
  • Roadmap/04 - CADENAS DE CARACTERES/javascript

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const contatenacion = 'hola' + ' mundo'; // hola mundo
2+
const longitud = 'hola'.length; // 4
3+
const caractereseEsp = 'hola'.charAt(0); // h
4+
const subcadenas = 'hola'.substring(0, 2); // ho
5+
const mayus = 'hola'.toUpperCase(); // HOLA
6+
const minus = 'Hola'.toLowerCase(); // hola
7+
const repetir = 'hola'.repeat(3); // holaholahola
8+
const trim = ' hola '.trim(); // hola
9+
const includes = 'hola'.includes('o'); // true
10+
const indexOf = 'hola'.indexOf('o'); // 1
11+
const lastIndexOf = 'holaho'.lastIndexOf('o'); // 5
12+
const replace = 'hola'.replace('o', 'a'); // hala
13+
const slice = 'hola'.slice(0, 2); // ho
14+
const split = 'hola'.split(''); // ['h', 'o', 'l', 'a']
15+
const terminaCon = 'hola'.endsWith('a'); // true
16+
const empiezaCon = 'hola'.startsWith('h'); // true
17+
const comparacion = 'hola'.localeCompare('hola'); // 0
18+
19+
20+
console.log(contatenacion, longitud, caractereseEsp, subcadenas, mayus, minus, repetir, trim, includes, indexOf, lastIndexOf, replace, slice, split, terminaCon, empiezaCon, comparacion);
21+
22+
23+
/* EXTRA
24+
* Crea un programa que analice dos palabras diferentes y realice comprobaciones
25+
* para descubrir si son:
26+
* - Palíndromos
27+
* - Anagramas
28+
* - Isogramas
29+
*/
30+
31+
function palindromo(palabra) {
32+
const palabraInvertida = palabra.split('').reverse().join('');
33+
return palabra === palabraInvertida;
34+
}
35+
36+
function anagrama(palabra1, palabra2) {
37+
return palabra1.split('').sort().join('') === palabra2.split('').sort().join('');
38+
}
39+
40+
function isograma(palabra) {
41+
const letras = palabra.split('');
42+
return letras.length === new Set(letras).size;
43+
}
44+
45+
console.log(palindromo('oso')); // true
46+
console.log(anagrama('roma', 'amor')); // true
47+
console.log(isograma('murcielago')); // true
48+
console.log(isograma('oso')); // false
49+
console.log(palindromo('hola')); // false
50+
console.log(anagrama('rama', 'amor')); // false

0 commit comments

Comments
 (0)