Skip to content

Instantly share code, notes, and snippets.

@Kyngo
Last active May 5, 2022 13:39
Show Gist options
  • Save Kyngo/70ad5207fb138dc0ec141d9731d092f2 to your computer and use it in GitHub Desktop.
Save Kyngo/70ad5207fb138dc0ec141d9731d092f2 to your computer and use it in GitHub Desktop.
Obtener la letra del DNI a través del número (NodeJS)
/**
* 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