Created
November 4, 2014 13:28
-
-
Save weslley39/988b709c955f04e76a30 to your computer and use it in GitHub Desktop.
PadLeft_PadRight_Js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
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