var testStr = 'Строка 1\nСтрока 2\nСтрока 3\nСтрока 4\nСтрока 5'.split('\n')
testStr = testStr.splice(0, 2).join('\n') + '\n' + testStr.join(' ')
console.log(testStr)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
table
{
width: 90%;
left: 5%;
margin-bottom: 10px;
position: relative;
}
td
{
text-align: center;
font-weight: bold;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td>a</td>
<td>aa</td>
<td>text 1</td>
</tr>
<tr>
<td>a</td>
<td>aa</td>
<td>text 2</td>
</tr>
<tr>
<td>b</td>
<td>aa</td>
<td>text 3</td>
</tr>
<tr>
<td>b</td>
<td>bb</td>
<td>text 4</td>
</tr>
<tr>
<td>b</td>
<td>bb</td>
<td>text 5</td>
</tr>
<tr>
<td>c</td>
<td>bb</td>
<td>text 6</td>
</tr>
<tr>
<td>c</td>
<td>cc</td>
<td>text 7</td>
</tr>
</table>
<div id="answerPlace"></div>
</body>
<script type="text/javascript" src ="http://localhost/Script/js/jQuery/jquery-1.11.2.min.js">
</script>
<script type="text/javascript">
function buildColumnArray(columnIndex)
{
var tempArray = new Array();
var column = $('table tr').find('td:eq(' + columnIndex + ')');
var cellText = '';
var content = $(column[0]).text();
var repeatAmount = 0;
column.each(function(index, item)
{
if($(item).text() != content)
{
tempArray.push
({
'value' : content,
'repeatAmount': repeatAmount,
'cellText': cellText.substr(0, cellText.length - 1)
});
content = $(item).text();
cellText = $(item).text() + ';';
repeatAmount = 1;
}
else
{
repeatAmount++;
cellText += $(item).next().text() + ';';
}
});
tempArray.push
({
'value' : content,
'repeatAmount': repeatAmount,
'cellText': cellText.substr(0, cellText.length - 1)
});
return tempArray;
}
function buildSimpleTable()
{
resultTable = '<table border="1">';
$('table tr').find('td:last').each(function(index, item)
{
resultTable += '<tr><td>' + $(item).text() + '</td></tr>';
});
resultTable += '</table>';
}
function appendRowSpan()
{
columnData.forEach(function(item)
{
var rowIndex = 0;
item.forEach(function(item)
{
$(resultTable).find('tr:eq(' + rowIndex + ')').
prepend('<td rowspan="' + item.repeatAmount + '">' + item.value + '</td>');
rowIndex += item.repeatAmount;
});
});
}
var columnData = new Array();
var columnAmount = $('table tr:eq(0) td').length - 1;
var resultTable = '';
$(document).ready(function()
{
while(columnAmount > 0)
{
columnData.push(buildColumnArray(columnAmount - 1));
columnAmount--;
}
buildSimpleTable();
resultTable = $(resultTable);
appendRowSpan();
$('#answerPlace').append(resultTable);
});
</script>
</html>