Solution Review: Length of a String
This review provides a detailed analysis of the solution to find the length of a string recursively.
We'll cover the following...
Solution: Using Recursion
Press + to interact
function recursiveLength(testVariable) {// Base caseif (testVariable === "") {return 0;}// Recursive caseelse {return 1 + recursiveLength(testVariable.substr(1));}}// Driver CodetestVariable = "Educative";console.log(recursiveLength(testVariable));
Explanation
In Javascript it is preferable to use
.length
function for finding the length of a string. However, this exercise is meant as practice. Here we teach how to find the length of a string recursively. Also, this ...