Created
January 13, 2014 07:58
-
-
Save composite/8396308 to your computer and use it in GitHub Desktop.
Which do you like more smallest script of 2 padLeft functions?
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 pad1(str,char,loop){ | |
| var result = ''; | |
| for(var i=0;i<loop;i++) result+=char; | |
| return (result+str).slice(-loop); | |
| } | |
| function pad2(str,char,loop){ | |
| for(var i=0,len=loop-str.length;i<len;i++) | |
| str = char + str; | |
| return str; | |
| } | |
| alert(pad1('12','0',4)); | |
| alert(pad2('12','0',4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment