View difference between Paste ID: NgZW66cr and rDja691y
SHOW: | | - or go back to the newest paste.
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);
10+
console.log(pad.substring(0, pad.length - str.length) + str); //This will print on the console -> '00001100'