Romzes,
без комментариев ... ввести места в инпуты(1...6), получить результат
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.total tr td:last-child {
color: #FF0000;
font-size: 28px
}
td {
height: 22px; width: 80px; text-align: center;
font-weight: bold;
}
</style>
</head>
<body>
<div class="refferee"></div>
<div class="total"></div>
<script>
function fn(f) {
var c = f.map(function(a, g) {
for (var d = [], b = 1, e = f.length; b <= e; b++) {
var c = a.filter(function(a) {
return a == b
}).length;
d.push(c)
}
return d
});
c.slice(0).sort(function(a, c) {
for (var d, b = 0, e = a.length; b < e; b++)
if (d = c[b] - a[b]) return d;
return 0
}).forEach(function(a, c) {
a.push(++c)
});
return c
}
function createTable(row, col, parent, mas) {
var table = document.createElement("table"),
arr = [];
var f = function(a, b, c) {
return function() {
arr[a][b] = +c.value || 0;
var res = fn(arr);
out(res)
}
};
for (var i = 0; i < row; i++) {
var tr = table.insertRow(i);
arr[i] = [];
for (var j = 0; j < col; j++) {
var td = tr.insertCell(j);
if (mas) td.textContent = mas[i][j];
else {
arr[i][j] = 0;
var input = document.createElement("input");
input.addEventListener("input", f(i, j, input));
td.appendChild(input)
}
}
}
parent.appendChild(table);
return arr
}
function out(arr) {
total.innerHTML = "";
createTable(arr.length, arr[0].length, total, arr)
}
var total = document.querySelector(".total");
var refferee = document.querySelector(".refferee");
var mas = createTable(6, 5, refferee);
var res = fn(mas);
out(res);
</script>
</body>
</html>