I understand why my original attempt was working… exponentially … against the goal haha
my most recent attempt seems to still replicate the data in the last array position improperly or something…
Are you sure you want to change the value of the original string you are using to add the repeats? If you can’t see what this is doing then add console.log(str) after the second line and then repeatStringNumTimes("a", 10) below the function.
Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number. For the purpose of this challenge, do not use the built-in .repeat() method.
Did you try adding the console.log like I suggested and then calling the function as I suggested? That will show you what is happening to the variable str each time through the loop and will hopefully allow you to realize what is going on.
But if you don’t want to do that then just try a real world example on paper. Let’s call the function as follows:
repeatStringNumTimes("a", 3);
This is the main part of the function:
The first time through the loop (i = 1) we do the following:
strArr.push('a'); // This makes strArr = ['a']
str = strArr.join(""); // This sets str to "a"
So far so good. Now the second time through the loop (i = 2) we do the following:
strArr.push('a'); // This makes strArr = ['a', 'a']
str = strArr.join(""); // This sets str to "aa"
Again, so far so good. Now the third time through the loop (i = 3), I’ll let you fill in the values. Remember, at this point, str = "aa".
strArr.push(str); // What is the value we are pushing here?
// What will the value of strArr be?
str = strArr.join(""); // What is the value of str?