DRAFT: GENERATED BY CONTINUE
Description
The provided code in example.ts
for the repeat()
and factorial()
functions is not executing as expected.
Steps to Reproduce
- Run the code provided in
example.ts
with the following command: npm start example.ts
- Observe the output in the console.
Expected Behavior
The repeat()
function should return a string of "a" characters repeated 5 times, and the factorial()
function should return the correct factorial value of 3.
Actual Behavior
The repeat()
function throws an error and does not return the expected value, and the factorial()
function also throws an error and does not return the expected value.
Solution
The code for the repeat()
function should be updated to the following:
function repeat(num: number, str: string): string {
return str.repeat(num);
}
The code for the factorial()
function should be updated to the following:
function factorial(num: number): number {
if(num === 0 || num === 1) {
return 1;
}
return num * factorial(num - 1);
}
Expected Result
After the changes to the repeat()
and factorial()
functions have been made, rerunning the code provided in example.ts
should produce the following output in the console:
Additional Instructions
Please review the updated code and confirm that the issue has been resolved.