Skip to content

Instantly share code, notes, and snippets.

@lbeckman314
Last active April 12, 2018 00:41
Show Gist options
  • Select an option

  • Save lbeckman314/ea7e96faff5e5db59d3e361ee4f1206a to your computer and use it in GitHub Desktop.

Select an option

Save lbeckman314/ea7e96faff5e5db59d3e361ee4f1206a to your computer and use it in GitHub Desktop.
var x = tabler()
document.getElementById("string-table").innerHTML = x;
function tabler() {
var myString = `
Did you ever hear the tragedy of Darth
Plagueis The Wise? I thought not. It’s not a story the
Jedi would tell you. It’s a Sith legend. Darth Plagueis
was a Dark Lord of the Sith, so powerful and so wise he
could use the Force to influence the midichlorians to
create life… He had such a knowledge of the dark side
that he could even keep the ones he cared about from
dying. The dark side of the Force is a pathway to many
abilities some consider to be unnatural. He became so
powerful… the only thing he was afraid of was losing his
power, which eventually, of course, he did.
Unfortunately, he taught his apprentice everything
he knew, then his apprentice killed him in his sleep.
Ironic. He could save others from death, but not
himself.
`;
var cols = 6
var rows = 5
var myArray = myString.split(' ');
var multiple = myArray.length / rows;
var table = "<table>";
table = table + "<tr>";
var j = 0;
var m = 1;
for (var i=0; i < (cols * rows); i++)
{
if (i % cols == 0 && i > rows)
{
console.log(i);
table = table + "</tr><tr>";
}
table = table + "<td>";
for (j; j < (m * multiple / cols); j++)
{
table = table + myArray[j];
table = table + " ";
}
j += 1;
m += 1;
table = table + "</td>";
j -= 1;
}
table = table + "</table>";
return table;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment