Last active
August 29, 2015 14:21
-
-
Save rinp/6df2297b7b54898101ae to your computer and use it in GitHub Desktop.
0埋め(JavaScript)
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
function (length) { | |
return function (str) { | |
var max = length - str.length; | |
// 利用する文字列長を考慮の上で初期値を決めておく。 | |
var s = "0000"; | |
while (s.length < max) { | |
s += "00"; | |
} | |
return (s + str).slice(-length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Array.prototype.join()の速度があまりよくないのであれば、ループで回す方がいいのかも。
利用箇所:年月日の0埋め