Last active
January 16, 2016 12:05
-
-
Save sandhose/82163edae8c200ab395d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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