Last active
May 5, 2022 13:39
-
-
Save Kyngo/70ad5207fb138dc0ec141d9731d092f2 to your computer and use it in GitHub Desktop.
Obtener la letra del DNI a través del número (NodeJS)
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
/** | |
* Programa para determinar la letra de tu DNI | |
* (C) 2019 Arnau Martín | |
*/ | |
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.question('Introduce los números del DNI: ', (answer) => { | |
answer = parseInt(answer); | |
if (answer.toString().length != 8) { | |
console.log('Valor introducido no válido.'); | |
process.exit(1); | |
} | |
const charArray = ['T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E']; | |
const idChar = charArray[parseInt(answer) % charArray.length]; | |
console.log(`Tu letra del DNI es ${idChar}`); | |
rl.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment