## Description

Find the most efficient way to pad a number

## Test runner

Testing in
TestOps/sec
Lazy Man Way
``````(function(myInteger, paddingLength) {
myInteger = myInteger.toString();

var myIntegerLength = myInteger.length,

for (var i = 0; i < loopIterations; i++) {
}
}

})(50000, 22);``````
Reverse While Loop w / Array + slice()
``````(function(myInteger, paddingLength) {

var x = [];

x.push(0);
}

x.push(myInteger);
return x.slice(-(paddingLength - ("" + myInteger).length));

})(50000, 22);``````
Reverse While Loop w / Strignified Array + slice()
``````(function(myInteger, paddingLength) {

var x = [];

x.push(0);
}

x.push(myInteger);
x = x.join("");

return x.slice(-(paddingLength - ("" + myInteger).length));

})(50000, 22);``````
Reverse While Loop w / String + slice()
``````(function(myInteger, paddingLength) {

var x = "";

x += 0;
}

x += myInteger;

return x.slice(-(paddingLength - ("" + myInteger).length));

})(50000, 22);``````
Reverse While Loop w / Array length + slice()
``````(function(myInteger, paddingLength) {

var x = [];

x[x.length] = 0;
}

x[x.length] = myInteger;

return x.slice(-(paddingLength - ("" + myInteger).length)).join("");

})(50000, 22);``````
A Little Algorithm I devised
``````(function(myInteger, paddingLength) {

var intString = (myInteger + ""),
intLength = intString.length,
x = intString;

}
else {
var x = (Math.pow(10, 10) + "").substr(1),
s = "";

while (z--) {
s += x;
}

s += (Math.pow(10, r) + "").substr(1)

}
}

return x;

})(50000, 22);``````
A Little improved Algorithm I devised
``````(function(myInteger, paddingLength) {

var intString = (myInteger + ""),
intLength = intString.length,
x = intString;

}
else {
var x = (Math.pow(10, 10) + "").substr(1),
s = "";
z = paddingLength / 10 >> 0;

while (z--) {
s += x;
}

s += (Math.pow(10, r) + "").substr(1)

}
}

return x;

})(50000, 22);``````
Another slight improvement
``````(function(myInteger, paddingLength) {

var intString = (myInteger + ""),
intLength = intString.length,
x = intString;

}
else {
var x = (Math.pow(10, 10) + "").substr(1),
s = "";
z = paddingLength / 10 >> 0;

while (z--) {
s = s + x;
}

s = s + (Math.pow(10, r) + "").substr(1)

}
}

return x;

})(50000, 22);``````
A slightly little bit more improved
``````(function(myInteger, paddingLength) {

var intString = myInteger >> 0,
intLength = intString % 10,
x = intString,
s = "",
z;

else {
x = (Math.pow(10, 10) + "").substr(1);
z = paddingLength / 10 >> 0;

while (z--)
s = s + x;

s = s + (Math.pow(10, r) + "").substr(1)

}
}

return x;

})(50000, 22);``````
Yet another attempt at a squeeze
``````(function(myInteger, paddingLength) {

var intString = myInteger >> 0,
intLength = intString % 10,
x = intString,
s = "",
z;

else {
x = String(Math.pow(10, 10)).substr(1);
z = paddingLength / 10 >> 0;

while (z--)
s = s + x;

s = s + (String(Math.pow(10, r))).substr(1);

}
}

return x;

})(50000, 22);``````

## Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.