|
To me this looks like perl golfing, but for some reason perl golfing is bad but writing extremely terse functional programs is not. Personally I like to combine both approaches. In swift I would write something like this: let l = ["abc", "ab", "abcdef", "abcdefgh"]
width = l.reduce(0, { max($0, $1.count) })
let centered = l.map({
(line: String) -> String in
var padding = (width - line.count) / 2
return String(repeating:" ", count: padding) + line
})
|