-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (43 loc) · 1.15 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const form = document.getElementsByTagName("form")[0];
form.addEventListener("submit", onSubmit);
/**
*
* @param {Event} event
*/
function onSubmit(event)
{
event.preventDefault();
const data = new FormData(form);
const values = Array.from(data.entries());
const [frmNumero] = values;
const numero = frmNumero[1];
alert(calcularDigitos(numero));
}
let setDeNumeros = {
2: ['a', 'b', 'c'],
3: ['d', 'e', 'f'],
4: ['g', 'h', 'i'],
5: ['j', 'k', 'l'],
6: ['m', 'n', 'o'],
7: ['p', 'q', 'r', 's'],
8: ['t', 'u', 'v'],
9: ['w', 'x', 'y', 'z'],
};
function calcularDigitos(digitos) {
if (!digitos.length) {
return [];
}
let previaCombinacion = [''];
for (let i = 0; i < digitos.length; i++) {
let nuevaCombinacion = [];
for (let x = 0; x < previaCombinacion.length; x++) {
for (let letra of setDeNumeros[digitos[i]]) {
nuevaCombinacion.push(previaCombinacion[x].concat(letra));
}
}
if (i == digitos.length - 1) {
return nuevaCombinacion;
}
previaCombinacion = nuevaCombinacion;
}
};