DEV Community

Discussion on: Practicing Recursion with 7 Algorithm Challenges

Collapse
 
stjrna profile image
stjrna

hi Annie I am somehow novice with js .. but not in programming .. I used to get fb page with programming challenges puzzles .. but I am trying not to use fb.. mostly fb is a waste of time .. anyway I am from older school I prefer to use as less as functions calls.. and I enjoy problems solving .. wish you happy coding

str = 'covid';
console.log(str);

strv = revstr(str,0);
console.log(strv);

// this mostly solve all of the puzzles with slight modification ;)
// you dont need to use costly sub function in the same time you can reverse part if you like
// ex s = reverstr(str,3) = codiv
function revstr(str, idx)
{
if (idx == str.length)
return '';
else
return revstr(str, idx+1)+str[idx];
}