I've been working on this project, and I have this array set up that I populate with the following:
var myArray = {};
myArray[idNumber] = parentIdNumber;
Each member can only have one or no parent, denoted by 0. I have values up to 70 filled out.
I'm receiving a value input
and need to check if every member of the array is in the 'family line' of input
.
So I iterate through myArray
and call isInFamilyLine(currentObject, 37)
, where currentObject
is in the range 1-70:
function isInFamilyLine(idNumber, input) {
if (idNumber== input) {
isInLine = true;
} else {
if (myArray[idNumber] == 0) {
isInLine = false;
} else {
isInLine = isInFamilyLine(myArray[idNumber], input);
}
}
return isInLine;
}
I think the logic is right, but most examples I've seen of too much recursion involved a bug in the code.
What's also weird is that the too much recursion
error is thrown on this line:
if (myArray[idNumber] == 0) {
Any ideas?