Last active
February 13, 2017 16:36
-
-
Save moqmar/9ef4f0755d0a17b61458f35b91447bc1 to your computer and use it in GitHub Desktop.
Leftpad, as it has to be: simple, fast, flexible
This file contains 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
// Leftpad - P(value, length, character, rightpad) - https://gist.github.com/moqmar/9ef4f0755d0a17b61458f35b91447bc1 | |
function P(v,l,c,r) { v = v.toString(); while (v.length < l) v = r ? v + (c||0) : (c||0) + v; return v; } | |
// Usage: P(value, length, character, rightpad) | |
// P(25, 3) ➜ "025" | |
// P(1, 3, " ") ➜ " 1" | |
// P(25, 4, ".", true) ➜ "25.." | |
// public domain / cc0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment