DESCRIPTION:
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.
Examples
repeatStringNumTimes("abc", 3)
//should return `abcabcabc`.
My approach for solving this problem:
- return “” if the num is negative.
- loop for num times
- storge the str value inside result var
- return the final result
My solution:
function repeatStringNumTimes(str, num) {
let result = ""
if(num<0){
return ""
}
for(let i =0;i<num;i++){
result += str
}
return result;
}
repeatStringNumTimes("abc", 3);
I breath with your support, sometimes I feel discouraged when I don’t get reactions on my posts. so please Like 👍 & share if you can. Thanks for being here!
Follow Muhmmad Awd on
If you have any questions or feedback, please feel free to contact me at