edit_markdown_table(`
|key|value|
|:-|-:|
|a|1|
|b|2|
|c|3|
`, [1, 0])
key | value |
---|---|
a | 1 |
b | 2 |
c | 3 |
value | key |
---|---|
1 | a |
2 | b |
3 | c |
function edit_markdown_table(a, w) { | |
const b = a.trim().split('\n') | |
const o = [] | |
for (let i = 0; i < b.length; i++) { | |
const c = b[i].split('|') | |
c.shift() | |
c.pop() | |
const d = [""] | |
const r = d.concat(w.map(e => c[e])) | |
r.push("") | |
o.push(r.join('|')) | |
} | |
return o.join('\n') | |
} |