Skip to content

Instantly share code, notes, and snippets.

@mayashavin
Created January 14, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayashavin/bc07f5d67a24b6101354bfc55e324a32 to your computer and use it in GitHub Desktop.
Save mayashavin/bc07f5d67a24b6101354bfc55e324a32 to your computer and use it in GitHub Desktop.
//Input: Array of Arrays of Cells
var grid = [['name', 'height', 'country'],
['Kilimanjaro',5895, 'Tanzania'],
['Everest',8848,'Nepal'],
['Mount Fuji',3776,'Japan'],
['Mont Blanc',4808,'Italy/France'],
['Vaalserberg',323,'Netherlands'],
['Denali', 6168,'United States'],
['Popocatepetl', 5465,'Mexico']];
function getColWidths(rows){
var colWidths = [];
for (var i = 0; i < rows[0].length; i++){
colWidths.push(rows.reduce(function(maxWidth, row){
return Math.max(maxWidth, row[i].length);
}, 0);
}
}
function getRowHeight(rows){
}
function Cell(content){
var content = content;
return{
minWidth: function(){ return content.length;},
minHeight: function(){ return 1;},
draw: function(width, height){
var cell = content;
for (var i = content.length; i < width; i++){
cell += " ";
}
return cell;
}
}
}
function drawTable(grid){
var colWidths = getColWidths(grid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment