Advertisement
DJ_Zoning

padLeft function

Jul 16th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function padLeft(width, char) {
  2.  var pad = '';
  3.  for (var i = 0; i < width; i++) {
  4.  pad += char;
  5.  }
  6.  return pad;
  7. }
  8. var str = '1100';
  9. var pad = padLeft(8, '0');
  10. console.log(pad.substring(0, pad.length - str.length) + str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement