3 ms·
Dear functional programmer, please do not slam on languages you do not even know how to program in. To be honest, I have no idea what this code is even supposed
by Traubenfuchs 7y ago
Dear functional programmer, please do not slam on languages you do not even know how to program in. To be honest, I have no idea what this code is even supposed to do and which idea of "centering" it satisfies. Whether this mess of Java or the mess of Haskell the blog writer created is more readable is up to you. C# has been functional forever and Java caught up a lot.
int maxLength = Stream.of(text).map(String::length).max(Integer::compareTo).get();
IntStream.range(0, text.length).forEach(i -> text[i] = " ".repeat((maxLength - text[i].length()) / 2) + text[i]);
(This becomes significantly more readable if you change the contract from passing an array of Strings to passing a list and returning a list. Since functional programmers are so in love with immutability: Java now provides immutable lists in the standard lib.)