let table = document.getElementById("mountains")
	.appendChild(document.createElement("table"));

let names = Object.keys(MOUNTAINS[0]);

let header = table.appendChild(document.createElement("tr"));
for (let name of names) {
	header.appendChild(document.createElement("th"))
		.appendChild(document.createTextNode(name));
}

for (let mountain of MOUNTAINS) {
	let row = table.appendChild(document.createElement("tr"));
	for (let name of names) {
		let textNode = row.appendChild(document.createElement("td"))
			.appendChild(document.createTextNode(mountain[name]));

		if (typeof mountain[name] == "number") {
			textNode.parentNode.style.textAlign = "right";
		}
	}
}

@@ -1,12 +1,85 @@
+function addTable(id, data) %7B%0A%09const headerTag = %22th%22, dataTag = %22td%22;%0A%0A%09
 let table = 
@@ -106,21 +106,13 @@
 yId(
-%22mountains%22
+id
 )%0A
+%09
 %09.ap
@@ -160,143 +160,61 @@
 );%0A%0A
-let names = Object.keys(MOUNTAINS%5B0%5D);%0A%0Alet header = table.appendChild(document.createElement(%22tr%22));%0Afor (let name of names) %7B%0A%09hea
+%09function appendCell(node, tag, text) %7B%0A%09%09return no
 de
-r
 .app
@@ -249,15 +249,15 @@
 ent(
-%22th%22
+tag
 ))%0A
+%09
 %09%09.a
@@ -295,61 +295,67 @@
 ode(
-name
+text
 ));%0A
+%09
 %7D%0A%0A
-for (let mountain of MOUNTAINS) %7B%0A%09let row
+%09let names = Object.keys(data%5B0%5D);%0A%0A%09let header
  = t
@@ -407,54 +407,136 @@
 );%0A%09
-for (let name of names) %7B%0A%09%09let textNode = row
+names.forEach(function(name) %7B%0A%09%09appendCell(header, headerTag, name);%0A%09%7D);%0A%0A%09data.forEach(function(mountain) %7B%0A%09%09let row = table
 .app
@@ -573,53 +573,90 @@
 t(%22t
-d%22))%0A%09%09%09.appendChild(document.createTextNode(
+r%22));%0A%09%09names.forEach(function(name) %7B%0A%09%09%09let textNode = appendCell(row, dataTag, 
 moun
@@ -666,20 +666,20 @@
 n%5Bname%5D)
-)
 ;%0A%0A
+%09
 %09%09if (ty
@@ -713,16 +713,17 @@
 ber%22) %7B%0A
+%09
 %09%09%09textN
@@ -770,11 +770,55 @@
 ;%0A%09%09
+%09
 %7D%0A
+%09
 %09%7D
-%0A%7D
+);%0A%09%7D);%0A%7D%0A%0AaddTable(%22mountains%22, MOUNTAINS);
 %0A

Refactor table function