Skip to content

Instantly share code, notes, and snippets.

@paulcarey
Last active June 12, 2019 08:38
Show Gist options
  • Save paulcarey/c33d1834f0395257ddbaea992c9a0fd4 to your computer and use it in GitHub Desktop.
Save paulcarey/c33d1834f0395257ddbaea992c9a0fd4 to your computer and use it in GitHub Desktop.
def f(s: String) = {
val xs = s.split("\n").map(_.split(","))
val ys = xs.transpose.map(_.map(_.length).max)
val zs = xs.map(_.zip(ys))
val ls = zs.map(_.map { case (x,y) => x.padTo(y, ' ') }.mkString(" "))
ls.mkString("\n")
}
val s = """aaa,b,cc
|a,bbbbb,c""".stripMargin
f(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment