-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_decimo_ejercicio.js
80 lines (63 loc) · 2.34 KB
/
10_decimo_ejercicio.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function operacion() {
var
tabla_vector = document.getElementById("vector"),
resultado = null,
vectorCreado = [
[2,4,6,8],
[3,6,9,12],
[5,7,10,11],
],
sumaFilas = [0,0,0],
sumaColumnas = [0,0,0,0];
let
row_id = document.createElement('tr'),
row_id2 = document.createElement('tr'),
cell_id_empty = document.createElement('td');
row_id.appendChild(cell_id_empty);
tabla_vector.appendChild(row_id);
for(i = 0; i < vectorCreado.length; i++)
{
let row = document.createElement('tr');
// Suma filas y columnas
for(j = 0; j < vectorCreado[i].length; j++) {
if(i == 0){
let cell_id = document.createElement('td');
cell_id.innerHTML = "Columna "+(j+1);
row_id.appendChild(cell_id);
if(j+1 >= vectorCreado[i].length) {
let suma_fila = document.createElement('td')
suma_fila.innerHTML = "Suma fila "
row_id.appendChild(suma_fila);
}
}
if(j == 0) {
let cell_id = document.createElement('td');
cell_id.innerHTML = "Fila "+(i+1);
row.appendChild(cell_id);
}
let
elementoActual = vectorCreado[i][j],
cell = document.createElement('td');
cell.innerHTML = String(elementoActual);
row.appendChild(cell);
sumaFilas[i] += elementoActual;
sumaColumnas[j] += elementoActual;
if(j+1 >= vectorCreado[i].length) {
let cell_suma_fila = document.createElement('td')
cell_suma_fila.innerHTML = sumaFilas[i];
row.appendChild(cell_suma_fila);
}
}
tabla_vector.appendChild(row);
}
let suma_columna = document.createElement('td');
suma_columna.innerHTML = "Suma columna "
row_id2.appendChild(suma_columna);
tabla_vector.appendChild(row_id2);
for(i = 0; i < sumaColumnas.length; i++) {
let suma_columna_cell = document.createElement('td');
suma_columna_cell.innerHTML = sumaColumnas[i];
row_id2.appendChild(suma_columna_cell);
}
}
operacion();