Skip to content

Instantly share code, notes, and snippets.

@weslley39
Created November 4, 2014 13:28
Show Gist options
  • Save weslley39/988b709c955f04e76a30 to your computer and use it in GitHub Desktop.
Save weslley39/988b709c955f04e76a30 to your computer and use it in GitHub Desktop.
PadLeft_PadRight_Js
// Pad Right
String.prototype.padRight = function (l, c) {
return this + Array(l - this.length + 1).join(c || " ");
}
// Pad Left
String.prototype.padLeft = function (l, c) {
return Array(l - this.length + 1).join(c || " ") + this;
}
// Print
var print = function (val) {
document.body.innerHTML = document.body.innerHTML + "<br />" + val
}
// Function Call
print("String Padding Right Side".padRight(40, "!"))
print("Text Padding ".padRight(20, "Right ") + "<br />")
print("Javascript Pad ".padLeft(20, "Left "))
print("Javascript Left ".padLeft(25, "Pad "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment