PILATONE,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
td{
border: 1px solid #008000;
text-align: center;
}
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
var a = document.querySelectorAll("tr");
[].forEach.call(a, function(c) {
var a = c.querySelectorAll("td");
[].reduce.call(a, function(a, b) {
if (b.textContent != a.textContent) return b;
a.colSpan++;
c.removeChild(b);
return a
})
})
});
</script>
</head>
<body>
<table id="table">
<tr>
<td></td>
<td>один</td>
<td>два</td>
<td>три</td>
<td>четыре</td>
<td>пять</td>
</tr>
<tr>
<td>два</td>
<td>3</td>
<td>3</td>
<td>5</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>три</td>
<td>3</td>
<td>8</td>
<td>5</td>
<td>9</td>
<td>9</td>
</tr>
<tr>
<td>четыре</td>
<td>2</td>
<td>8</td>
<td>5</td>
<td>9</td>
<td>5</td>
</tr>
<tr>
<td>пять</td>
<td>2</td>
<td>5</td>
<td>5</td>
<td>4</td>
<td>4</td>
</tr>
</table>
</body>
</html>