by rootlocus · 10y ago · 0 comments
If you can't trust yourself to write such a simple function, how confident are you about writing something a little more complicated? Or very complicated? Doesn't it bother you that you feel more confident in 10 simple lines of code written by a complete stranger than you are in yourself?
Although I agree with you about the left pad function. It wouldn't even cross my mind to search for a library instead of just typing out the code.
It does make sense as a function in a larger utilities library though, such as lodash. If you already have that as part of your code base then might as well take advantage, similar to apache commons/lang in the java world.
That's OK, someone did it for you:
https://metacpan.org/pod/Text::Trim
CPAN to the rescue!