Skip to content

Commit

Permalink
Merge pull request #6251 from almarro1/reto47-javascript
Browse files Browse the repository at this point in the history
Reto #47 - javascript
  • Loading branch information
Roswell468 authored Jan 19, 2024
2 parents f9a7440 + 85b5828 commit 7c6fe52
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

function puntuacion(palabra) {
return palabra
//convertir a mayúsculas
.toUpperCase()
.replaceAll(/[ÁÀÄ]/g, 'A')
.replaceAll(/[ÉÈË]/g, 'E')
.replaceAll(/[ÍÌÏ]/g, 'I')
.replaceAll(/[ÓÒÖ]/g, 'O')
.replaceAll(/[ÚÙÜ]/g, 'U')
// separar palabra en letras
.split('')
// eliminar todo lo que no sea A-Z
.filter(letter => letter >= 'A' && letter <= 'Z')
// pasar letra a valor según su código ascii
.map(letter => letter.charCodeAt() - 64)
.reduce((total, curr) => total + curr, 0);
}

const palabras = [
'matrimonio', 'tarántula', 'arizónico', 'zoológico', 'zoólogo', 'pensamiento'
];
console.log('EJEMPLOS:')
palabras.forEach(palabra => console.log(`${palabra} -> ${puntuacion(palabra)}`));

const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout, prompt: 'guess>' });

async function main() {
let found = false;
while (!found) {
const palabra = await new Promise(resolve => readline.question('Introduce una palabra: ', resolve));
const valor = puntuacion(palabra);
console.log(`La palabra "${palabra}" tiene un valor de ${valor} puntos`);
if (valor === 100) {
console.log('¡Enhorabuena, has encontrado la palabra de 100 puntos!');
found = true;
}
}
process.exit();
}

main();

0 comments on commit 7c6fe52

Please sign in to comment.