Given a string str and number n , write a program in Javascript that recursively appends a copy of string str n times and returns the resulting string in a sentence explaining whether the resulting...


Given a string
str
and number
n, write a program in Javascript  that recursively appends a copy of string
str
n
times and returns the resulting string in a sentence explaining whether the resulting string has an odd or even amount of the passed instr. For example:


RecuriveCopy("a", 10)
//-> "aaaaaaaaaaa has a(n) odd number of a's"


RecursiveCopy("blah",5)
//-> "blahblahblahblahblahblah has a(n) even number of blah's"


Please complete the following function:
function RecursiveCopy(str, n) {
// your code here
}


The problem must satisfy the following:



  • You must use recursion.

  • You should end up with

    n+1 copies of the str

    total in the output because you are appending additionalstrcopies.

  • Use string literal formatting for the output


Hints:



  • Consider using two functions, one to handle the recursion and one stand-in function (shim) to take the result and generate the string output.

    • For example: the root function, RecursiveCopy(str, n), actually calls another function inside called Recurse(str, n), where Recurse(str, n) returns resulting string after the recursive copying.



  • Since you know that you need n+1 copies of the str, as long as you know n, you can deduce if the expected output will have an even or odd number of copies.



Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here