I am practicing using recursive functions to solve some simple javascript problems.
I am running into an issue with the following code,
var locate = function(arr,value){
for (var i=0; i <arr.length; i++) {
if(typeof arr[i]=== "string") {
console.log("string is string");
if(arr[i]=== value) {
console.log("This should be true");
return true;
}
}
else {
locate(arr[i], value);
}
}
}
console.log(locate(['d', 'a',['e', 'g']], 'e'));
I cannot get this program to return true. It gets to the right part of the code, as it prints the statement above it.
Any help would be appreciated. I have been banging my head at this for a couple of hours now.
Edit-@Matt Burland pointed out the fact that you need to include a return statement when calling the recursive.
undefined