The advanced code solution to the challenge Basic Algorithm Scripting: Repeat a String Repeat a String isn’t accepted; the challenge doesn’t allow you to use the built-in repeat()
method. Not sure if this is intentional and the advanced solution is just there to show people another way to do it – if so, it seems like the solution should state that it won’t pass the challenge.
Another minor issue with the challenge solutions: in the intermediate code solution, below, num < 0
should be changed to num < 1
since the challenge says to return an empty string if num isn’t a positive number.
function repeatStringNumTimes(str, num) {
if(num < 0)
return "";
if(num === 1)
return str;
else
return str + repeatStringNumTimes(str, num - 1);
}