Last active
December 20, 2015 17:19
-
-
Save ianpgall/6168164 to your computer and use it in GitHub Desktop.
JavaScript function that pads the left side of a string/number with a specific prefix, up to a specific length
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
var PadText = (function () { | |
"use strict"; | |
var func; | |
func = function (text, prefix, finalLength) { | |
return (new Array(finalLength).join(prefix.charAt(0)) + text).slice(-finalLength); | |
}; | |
return func; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment