Skip to content

Instantly share code, notes, and snippets.

@sandhose
Last active January 16, 2016 12:05
Show Gist options
  • Save sandhose/82163edae8c200ab395d to your computer and use it in GitHub Desktop.
Save sandhose/82163edae8c200ab395d to your computer and use it in GitHub Desktop.
'use strict';
let printf = require('printf');
let run = (sep, sheet) => {
let recordFmt = col => '%-' + Math.max(...(sheet.map(line => line[col].length))) + 's';
let fmt = sheet[0].map((e, i) => recordFmt(i)).join(sep);
return sheet.map(line => printf(fmt, ...line)).join('\n');
}
let sheet = `to#titi#ta#tutu#a
toto#ti#tata#tu#b`.split('\n').map(e => e.split('#'));
console.log(run('#', sheet));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment