Reply to post: Re: Left padding

How one developer just broke Node, Babel and thousands of projects in 11 lines of JavaScript

mark jacobs
Boffin

Re: Left padding

function leftpad(str,len,ch)

{

var s1='                                                ';

var s2='0000000000000000000000000000000000000000';

if (ch) if (ch=='0') return s2.substr(0,len-str.length)+str;

return s1.substr(0,len-str.length)+str;

}

et voilà!

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019