Question
Finding unique paths : Follow up
> function pathExists(shapeStart, shapeEnd):Boolean {
> for (var node in shapeStart) {
> for (var key in shapeStart[node].obj) {
> if (key == shapeEnd) {
> return true;
> } else {
> pathExists(key,shapeEnd);
> }
> }
> }
> return false;
> }
kglad...
I implemented your solution this morning but came up with the same type
of problem I was having before with my own recursive function.
Here is the code (modified from what you posted) that I am using:
function pathExists(shapeStart, shapeEnd):Boolean {
for (var i:Number = 0; i < allConnections[shapeStart].length; i++) {
if (allConnections[shapeStart] ._parent == shapeEnd) {
trace("shapeEnd found in list");
return true;
} else if (checkedParents.indexOf(allConnections[shapeStart].
_parent) == -1) {
checkedParents.push(allConnections[shapeStart] ._parent)
pathExists(allConnections[shapeStart]._parent,shapeEnd);
}
}
return false;
}
The problem is this... once the condition is met which returns true (I
know this condition is met because my trace works) it does not actually
return true to the initial caller. So, I end up with false being
returned. It is as if the true is being returned to the recursive call
and not to the original function call. Does that make sense?
Thanks...