Lazy Man Way | (function(myInteger, paddingLength) {
myInteger = myInteger.toString();
var myIntegerLength = myInteger.length,
paddingLength = paddingLength || 5,
loopIterations = paddingLength - myIntegerLength,
padding = "";
if (paddingLength > myIntegerLength) {
for (var i = 0; i < loopIterations; i++) {
padding = ["0", padding].join('');
}
}
return [padding, myInteger].join('');
})(50000, 22);
| ready |
Reverse While Loop w / Array + slice() | (function(myInteger, paddingLength) {
var x = [];
while (paddingLength--) {
x.push(0);
}
x.push(myInteger);
return x.slice(-(paddingLength - ("" + myInteger).length));
})(50000, 22);
| ready |
Reverse While Loop w / Strignified Array + slice() | (function(myInteger, paddingLength) {
var x = [];
while (paddingLength--) {
x.push(0);
}
x.push(myInteger);
x = x.join("");
return x.slice(-(paddingLength - ("" + myInteger).length));
})(50000, 22);
| ready |
Reverse While Loop w / String + slice() | (function(myInteger, paddingLength) {
var x = "";
while (paddingLength--) {
x += 0;
}
x += myInteger;
return x.slice(-(paddingLength - ("" + myInteger).length));
})(50000, 22);
| ready |
Reverse While Loop w / Array length + slice() | (function(myInteger, paddingLength) {
var x = [];
while (paddingLength--) {
x[x.length] = 0;
}
x[x.length] = myInteger;
return x.slice(-(paddingLength - ("" + myInteger).length)).join("");
})(50000, 22);
| ready |
A Little Algorithm I devised | (function(myInteger, paddingLength) {
var intString = (myInteger + ""),
intLength = intString.length,
x = intString;
if (paddingLength > intLength) {
if (paddingLength <= 20) {
x = ((Math.pow(10, paddingLength) + "").substr(1) + intString).slice(-paddingLength);
}
else {
var x = (Math.pow(10, 10) + "").substr(1),
s = "";
z = parseInt(paddingLength / 10);
while (z--) {
s += x;
}
r = paddingLength % 10;
s += (Math.pow(10, r) + "").substr(1)
x = (s + intString).slice(-paddingLength)
}
}
return x;
})(50000, 22);
| ready |
(NO LONGER) bitwise | var nums = ["0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000"];
var numStr = 50000 + "";
(nums[22 - numStr.length - 1]) + numStr;
| ready |