Last active
December 27, 2015 17:59
-
-
Save zfkun/7366882 to your computer and use it in GitHub Desktop.
create a repeat string by a string.
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
define(function() { | |
/** | |
* create a repeat string by a string | |
* | |
* @param {string} str target string | |
* @param {number} count repeat count | |
* @return {string} | |
*/ | |
function repeat( str, count ) { | |
return count < 1 ? str : new Array( count + 1 ).join( str ); | |
} | |
return repeat; | |
}); |
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
define(function() { | |
/** | |
* create a repeat string by a string | |
* | |
* @param {string} str target string | |
* @param {number} count repeat count | |
* @return {string} | |
*/ | |
function repeat( str, count ) { | |
var rs = str; | |
count = count || 0; | |
while ( count-- > 0 ) { | |
rs += str; | |
} | |
return rs; | |
} | |
return repeat; | |
}); |
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
define(function() { | |
/** | |
* create a repeat string by a string | |
* | |
* @param {string} str target string | |
* @param {number} count repeat count | |
* @return {string} | |
*/ | |
function repeat( str, count ) { | |
var rs = [ str ]; | |
count = count || 0; | |
while ( count-- > 0 ) { | |
rs.push( str ); | |
} | |
return rs.join( '' ); | |
} | |
return repeat; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment