Basic Algorithm Scripting: Repeat a String Repeat a String -- solution not accepted

Basic Algorithm Scripting: Repeat a String Repeat a String -- solution not accepted
0

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);
}

Hi @nataliecardot

Thank you for watching for things like this. It just so happens, the Advanced Solution was actually removed in pull request 35805 when it was merged on April 9th. It is no longer in the Guide in the master branch, but the change has yet to be deployed into production, so it will not actually show correctly just yet.

Regarding your other observation about the Intermediate Solution, you are correct. That solution should be updated. Would you be interested in creating a pull request to make this change? Also, since the incorrect solution would still pass the current tests, would you be interested in helping to add a new test which makes sure a blank string is returned when num = 0?

2 Likes

I created one pull request changing num < 0 to num < 1 and another adding a test checking that a blank string is returned when num is 0.