let fruit = "APPLE";
function reverseStringByRecursion(name) {
if (name.length == 0) {
return "";
} else {
let lastChar = name[name.length - 1];
let excludingLastChar = name.slice(0, name.length - 1);
return lastChar + reverse(excludingLastChar);
}
}
var reversedString = reverseStringByRecursion(fruit);
console.log(reversedString);
Output:
ELPPA
No comments:
Post a Comment