Hacker News new | ask | show | jobs
by wtbob 3687 days ago
This is simple:

    if (str.length < 6) {
      str = ' '.repeat(6-str.length) + str;
    }
This is easy:

    leftPad = require('left-pad')
 
    leftPad(str, 6)
(note: my JavaScript is rusty; there may be some very valid reason that the simple code is wrong)
1 comments

Thats one reason that its tempting to use something as simple as left pad. I only spend a small percentage of my time doing JavaScript, and the language has enough gotchas. Using something like that would give me the peace of mind that I haven't missed some quirk of the language. If someone knows how to publish a package on npm, then they probably know more JavaScript than me.