Open akmalist opened 6 years ago
function repeatStringNumTimes(str, num) {
var accumulatedStr = '';
while (num > 0) {
accumulatedStr += str;
num--;
}
return accumulatedStr;
function repeatStringNumTimes(str, num) {
if(num < 0)
return "";
if(num === 1)
return str;
else
return str + repeatStringNumTimes(str, num - 1);
}
function repeatStringNumTimes(str, num) {
return num > 0 ? str.repeat(num) : '';
}
repeatStringNumTimes("abc", 3);
using express routing :
app.get("/repeat/:link/:num", function(req,res){
function repeatMe(str , num){
str = req.params.link;
num = req.params.num;
if (num<1){
str =" ";
}else{
return (str+" ").repeat(num);
}
}
// console.log(req.params.link);
// console.log(req.params.num);
res.send(repeatMe(" link ", +" num "));
});