I have following function that display ASCII table
function ascii_table(array, header) {
if (!array.length) {
return \'\'
This can be done without any modification of your code by expanding your array
-- adding one new row for each extra line of the comment. The first row would be the same as before -- except that the comment cell contains only the first line of the comment. Every additional line would contain empty cells -- except the comment cell, which would contain that comment line.
I'd break out most of the functions for readability, but to keep with your coding style, it might look like this:
array = array.reduce(function (carry, originalRow) {
var commentLines = originalRow[4].split(/\n/g);
var rows = commentLines.map(function (commentLine, rowIndex) {
var newRow = originalRow.map(function (originalCellContent, columnIndex) {
var cellContent = '';
if (rowIndex === 0) {
cellContent = originalCellContent;
}
if (columnIndex === 4) {
cellContent = commentLine;
}
return cellContent;
});
carry.push(newRow);
});
return carry;
}, []);
A fork of your fiddle is here, with this code added.