Created
December 2, 2015 07:01
-
-
Save SerhiiLihus/6183ebf92dbd5fe86fb5 to your computer and use it in GitHub Desktop.
Repeat a string repeat 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
// Bonfire: Repeat a string repeat a string | |
// Author: @serhiilihus | |
// http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat%28str%2C%20num%29%20{%0A%20%20var%20newString%20%3D%20%22%22%3B%0A%20%20if%20%28%20num%20%3E%200%20%29%20{%0A%20%20for%20%28var%20i%20%3D%200%3B%20i%20%3C%20num%20%3B%20i%2B%2B%20%29%0A%20%20%20%20%20%20newString%20%2B%3D%20str%3B%0A%20%20return%20newString%3B%0A%20%20}%20else%20return%20%22%22%3B%0A}%0A%0Arepeat%28%22abc%22%2C%203%29%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function repeat(str, num) { | |
var newString = ""; | |
if ( num > 0 ) { | |
for (var i = 0; i < num ; i++ ) | |
newString += str; | |
return newString; | |
} else return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Мне кажется, что я проще реализовал